Getting the Windows Product ID using WMI

I needed to get the Windows Product ID from managed code recently and decided that using WMI would be the most reliable and stable way to get the job done. Do not follow any examples that show you how to get this information from the registry. You simply cannot rely on those registry keys being present in the many different versions of Windows. There is also no guarantee that if they are present, that this will continue to be the case into the future. Using an official and supported API means that maintaining compatibility is Microsoft’s problem and not yours.