0

我写了一个关于 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());
4

1 回答 1

0

你能试试我的代码吗

        ManagementClass wmi = new ManagementClass("Win32_OperatingSystem");
        foreach (var item in wmi.GetInstances())
        {
            string serialNumber = Convert.ToString(item["SerialNumber"]);
            Console.WriteLine(serialNumber);
        }
于 2019-02-22T12:08:33.507 回答