.net c# 通过ManagementClass初始化Win32_Keyboard信息,遍历获取键盘详细数值信息
源码:
/// <summary>
/// 其它硬件信息
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string PhicnalInfo()
{
StringBuilder str = new StringBuilder();
string name = "Win32_Keyboard";
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();
}
运行结果:
Availability:
Caption: 增强型(101 或 102 键)
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_Keyboard
Description: USB 输入设备
DeviceID: USB\VID_0603&PID_00FE&MI_00\6&1BF1F3C3&0&0000
ErrorCleared:
ErrorDescription:
InstallDate:
IsLocked:
LastErrorCode:
Layout: 00000804
Name: 增强型(101 或 102 键)
NumberOfFunctionKeys: 12
Password:
PNPDeviceID: USB\VID_0603&PID_00FE&MI_00\6&1BF1F3C3&0&0000
PowerManagementCapabilities:
PowerManagementSupported: False
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: WIN-SHENGWU
Availability:
Caption: 增强型(101 或 102 键)
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_Keyboard
Description: HID Keyboard Device
DeviceID: HID\VID_0603&PID_00FE&MI_01&COL01\7&78A8EA&0&0000
ErrorCleared:
ErrorDescription:
InstallDate:
IsLocked:
LastErrorCode:
Layout: 00000804
Name: 增强型(101 或 102 键)
NumberOfFunctionKeys: 12
Password:
PNPDeviceID: HID\VID_0603&PID_00FE&MI_01&COL01\7&78A8EA&0&0000
PowerManagementCapabilities:
PowerManagementSupported: False
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: WIN-SHENGWU
Availability:
Caption: 增强型(101 或 102 键)
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_Keyboard
Description: USB 输入设备
DeviceID: USB\VID_045E&PID_0745&MI_00\6&1EAC386F&0&0000
ErrorCleared:
ErrorDescription:
InstallDate:
IsLocked:
LastErrorCode:
Layout: 00000804
Name: 增强型(101 或 102 键)
NumberOfFunctionKeys: 12
Password:
PNPDeviceID: USB\VID_045E&PID_0745&MI_00\6&1EAC386F&0&0000
PowerManagementCapabilities:
PowerManagementSupported: False
Status: OK
StatusInfo:
SystemCreationClassName: Win32_ComputerSystem
SystemName: WIN-SHENGWU
图片运行效果: