我正在尝试使用C#获取有关当前计算机的一些数据。目前我正在使用ManagementObjectCollection
来检索信息,但它只适用于32位计算机,而不适用于64位计算机。使用Win32 Registry API
就可以通过传递RegistryView.Registry64
参数来读取正确的数据,但我不知道如何使用WMI类。任何帮助将不胜感激!谢谢。这是我尝试过的示例代码:
private static void GetInformation()
{
using (ManagementObjectSearcher windowsObject = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS"))
{
using (ManagementObjectCollection collection = windowsObject.Get())
{
foreach (ManagementObject managementObject in collection)
{
Console.WriteLine("Install Date:{0}", managementObject["InstallDate"]);
Console.WriteLine("OS Version: {0}.{1} Build {2}", managementObject["Version"], managementObject["BuildNumber"], managementObject["CodeSet"]);
Console.WriteLine("Product Id: {0}", managementObject["SerialNumber"]);
}
}
}
using (ManagementObjectSearcher windowsObject = new ManagementObjectSearcher("SELECT ProcessorID From Win32_processor"))
{
using (ManagementObjectCollection collection = windowsObject.Get())
{
foreach (ManagementObject managementObject in collection)
{
Console.WriteLine("Processor Id: {0}", managementObject["ProcessorID"]);
}
}
}
using (ManagementObjectSearcher windowsObject = new ManagementObjectSearcher("SELECT SerialNumber From Win32_BaseBoard"))
{
using (ManagementObjectCollection collection = windowsObject.Get())
{
foreach (ManagementObject managementObject in collection)
{
Console.WriteLine("Motherboard Id: {0}", managementObject["SerialNumber"]);
}
}
}
}