How to check Windows license status in C#?

試著忘記壹切 提交于 2019-12-06 05:55:17

The WMI class Win32_WindowsProductActivation is only supported on windows XP. For windows 10 you need to use SoftwareLicensingProduct

public static bool IsWindowsActivated()
{
    ManagementScope scope = new ManagementScope(@"\\" + System.Environment.MachineName + @"\root\cimv2");
    scope.Connect();

    SelectQuery searchQuery = new SelectQuery("SELECT * FROM SoftwareLicensingProduct WHERE ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f' and LicenseStatus = 1");
    ManagementObjectSearcher searcherObj = new ManagementObjectSearcher(scope, searchQuery);

    using (ManagementObjectCollection obj = searcherObj.Get())
    {
        return obj.Count > 0;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!