通过 ManagementObjectSearcher 类查询 Win32_OperatingSystem 信息,获取操作系统基础信息
源码:
/// <summary>
/// 其它硬件信息
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string PhicnalInfo()
{
StringBuilder str = new StringBuilder();
string name = "Win32_OperatingSystem";
ManagementClass osClass = new ManagementClass(name);
foreach (ManagementObject obj in osClass.GetInstances())
{
PropertyDataCollection pdc = obj.Properties;
foreach (PropertyData pd in pdc)
{
str.AppendLine(string.Format("{0}: {1}", pd.Name, pd.Value));
}
}
return str.ToString();
}
运行结果:
BootDevice: \Device\HarddiskVolume3
BuildNumber: 20348
BuildType: Multiprocessor Free
Caption: Microsoft Windows Server 2022 Datacenter
CodeSet: 936
CountryCode: 86
CreationClassName: Win32_OperatingSystem
CSCreationClassName: Win32_ComputerSystem
CSDVersion:
CSName: WIN-SHENGWU
CurrentTimeZone: 480
DataExecutionPrevention_32BitApplications: True
DataExecutionPrevention_Available: True
DataExecutionPrevention_Drivers: True
DataExecutionPrevention_SupportPolicy: 3
Debug: False
Description: Win-ShengWu
Distributed: False
EncryptionLevel: 256
ForegroundApplicationBoost: 2
FreePhysicalMemory: 12182936
FreeSpaceInPagingFiles: 5638412
FreeVirtualMemory: 14007660
InstallDate: 20211231113812.000000+480
LargeSystemCache:
LastBootUpTime: 20230213092201.500000+480
LocalDateTime: 20230217100008.961000+480
Locale: 0804
Manufacturer: Microsoft Corporation
MaxNumberOfProcesses: 4294967295
MaxProcessMemorySize: 137438953344
MUILanguages: System.String[]
Name: Microsoft Windows Server 2022 Datacenter|C:\WINDOWS|\Device\Harddisk1\Partition1
NumberOfLicensedUsers: 0
NumberOfProcesses: 284
NumberOfUsers: 1
OperatingSystemSKU: 8
Organization:
OSArchitecture: 64 位
OSLanguage: 2052
OSProductSuite: 400
OSType: 18
OtherTypeDescription:
PAEEnabled:
PlusProductID:
PlusVersionNumber:
PortableOperatingSystem: False
Primary: True
ProductType: 3
RegisteredUser:
SerialNumber: 00456-50925-34111-AA867
ServicePackMajorVersion: 0
ServicePackMinorVersion: 0
SizeStoredInPagingFiles: 6291456
Status: OK
SuiteMask: 400
SystemDevice: \Device\HarddiskVolume3
SystemDirectory: C:\WINDOWS\system32
SystemDrive: C:
TotalSwapSpaceSize:
TotalVirtualMemorySize: 39810824
TotalVisibleMemorySize: 33519368
Version: 10.0.20348
WindowsDirectory: C:\WINDOWS
图片展示效果: