我写了一个关于Windows产品ID(序列号)的WMI查询,但它没有返回产品ID。这是什么原因?
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_OperatingSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_OperatingSystem instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("SerialNumber: {0}", queryObj["SerialNumber"]);
}
return Convert.ToString(searcher.ToString());
答案 0 :(得分:0)
您可以尝试我的代码
ManagementClass wmi = new ManagementClass("Win32_OperatingSystem");
foreach (var item in wmi.GetInstances())
{
string serialNumber = Convert.ToString(item["SerialNumber"]);
Console.WriteLine(serialNumber);
}