.net c# 通过ManagementClass初始化Win32_ComputerSystem信息,遍历获取计算机系统信息
源码:
/// <summary>
/// 其它硬件信息
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string PhicnalInfo()
{
StringBuilder str = new StringBuilder();
string name = "Win32_ComputerSystem";
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();
}
运行结果:
AdminPasswordStatus: 0
AutomaticManagedPagefile: True
AutomaticResetBootOption: False
AutomaticResetCapability: True
BootOptionOnLimit:
BootOptionOnWatchDog:
BootROMSupported: True
BootStatus: System.UInt16[]
BootupState: Normal boot
Caption: WIN-SHENGWU
ChassisBootupState: 3
ChassisSKUNumber: To be filled by O.E.M.
CreationClassName: Win32_ComputerSystem
CurrentTimeZone: 480
DaylightInEffect:
Description: AT/AT COMPATIBLE
DNSHostName: Win-ShengWu
Domain: WORKGROUP
DomainRole: 2
EnableDaylightSavingsTime: True
FrontPanelResetStatus: 0
HypervisorPresent: False
InfraredSupported: False
InitialLoadInfo:
InstallDate:
KeyboardPasswordStatus: 0
LastLoadInfo:
Manufacturer: Gigabyte Technology Co., Ltd.
Model: B85M-DS3H-A
Name: WIN-SHENGWU
NameFormat:
NetworkServerModeEnabled: True
NumberOfLogicalProcessors: 8
NumberOfProcessors: 1
OEMLogoBitmap:
OEMStringArray: System.String[]
PartOfDomain: False
PauseAfterReset: -1
PCSystemType: 1
PCSystemTypeEx: 1
PowerManagementCapabilities:
PowerManagementSupported:
PowerOnPasswordStatus: 0
PowerState: 0
PowerSupplyState: 3
PrimaryOwnerContact:
PrimaryOwnerName:
ResetCapability: 1
ResetCount: -1
ResetLimit: -1
Roles: System.String[]
Status: OK
SupportContactDescription:
SystemFamily: To be filled by O.E.M.
SystemSKUNumber: To be filled by O.E.M.
SystemStartupDelay:
SystemStartupOptions:
SystemStartupSetting:
SystemType: x64-based PC
ThermalState: 3
TotalPhysicalMemory: 34323832832
UserName: WIN-SHENGWU\Administrator
WakeUpType: 6
Workgroup: WORKGROUP
图片展示效果: