I have a piece of old code that used a query using WQL to get in from the Win32_WindowsProductActivation class.
SELECT * FROM Win32_WindowsProductActivation
It then itterated over it and essentialy got the ProductID string using
hres = pclsObj->Get("ProductID", 0, &vtProp, 0, 0);
and
return WideString(vtProp.bstrVal);
I wanna clean this up a bit and also wanted to make it function in Windows 7 and noticed that the support for the Win32_WindowsProductActivation class was dropped in Windows Vista. I also read that similar functionality is now provided by the Software Licensing Classes. How would the above look with its Software Licensing Classes equivalent?
I don’t seem to see which exat field would return the same value. Guessing ProductKeyID of the SoftwareLicensingProduct class. But there are others that sound like likley candidates to 🙂
The ProductID property of the Win32_WindowsProductActivation states
Now if you check the value of the
ProductKeyIDproperty of the SoftwareLicensingProduct WMI class in Windows 7, this not match with the ProductID of the System Properties dialog.The solution is use the
SerialNumberproperty of theWin32_OperatingSystem, this works in Windows XP, Vista and 7 (and Windows server editions too)