/// <summary>
/// 获取硬件及系统详细信息
/// ManagementClass
/// </summary>
public static class HardwareInformation
{
public enum HardWareType
{
/********************* 硬件信息 *********************/
/// <summary>
/// CPU中央处理器
/// </summary>
CPU = 0,
/// <summary>
/// 物理内存条
/// </summary>
PhysicalMemory = 1,
//点击设备
/// <summary>
/// 点击设备 鼠标,控制球(track ball),触控板
/// </summary>
PointingDevice = 2,
/// <summary>
/// 软驱
/// </summary>
FloppyDrive = 3,
/// <summary>
/// 磁盘- 硬盘
/// </summary>
DiskDrive = 4,
/// <summary>
/// 光驱
/// </summary>
CDROMDrive = 5,
/// <summary>
/// 主板
/// </summary>
BaseBoard = 6,
/// <summary>
/// BIOS 芯片
/// </summary>
BIOS = 7,
/// <summary>
/// 并口
/// </summary>
ParallelPort = 8,
/// <summary>
/// 串口
/// </summary>
SerialPort = 9,
/// <summary>
/// 串口配置
/// </summary>
SerialPortConfiguration = 10,
/// <summary>
/// 多媒体设备 ,声卡
/// </summary>
SoundDevice = 11,
/// <summary>
/// 主板插槽 ISA、PCI、AGP
/// </summary>
SystemSlot = 12,
/// <summary>
/// USB控制器
/// </summary>
USBController = 13,
/// <summary>
/// 网络适配器
/// </summary>
NetworkAdapter = 14,
/// <summary>
/// 网络适配器设置
/// </summary>
NetworkAdapterConfiguration = 15,
/// <summary>
/// 打印机
/// </summary>
Printer = 16,
/// <summary>
/// 打印机设置
/// </summary>
PrinterConfiguration = 17,
/// <summary>
/// 打印机任务
/// </summary>
PrintJob = 18,
/// <summary>
/// 打印机端口
/// </summary>
TCPIPPrinterPort = 19,
/// <summary>
/// MODEM
/// </summary>
POTSModem = 20,
/// <summary>
/// MODEM端口
/// </summary>
POTSModemToSerialPort = 21,
/// <summary>
/// 显示器
/// </summary>
DesktopMonitor = 22,
/// <summary>
/// 显卡
/// </summary>
DisplayConfiguration = 23,
/// <summary>
/// 显卡设置
/// </summary>
DisplayControllerConfiguration = 24,
/// <summary>
/// 显卡视频控制器
/// </summary>
VideoController = 25,
/// <summary>
/// 显卡支持的显示模式
/// </summary>
VideoSettings = 26,
/// <summary>
/// 键盘
/// </summary>
Keyboard = 27,
/**********************系统信息***********************/
/// <summary>
/// 时区
/// </summary>
TimeZone = 30,
/// <summary>
/// 驱动程序
/// </summary>
SystemDriver = 31,
/// <summary>
/// 磁盘分区
/// </summary>
DiskPartition = 32,
/// <summary>
/// 逻辑磁盘
/// </summary>
LogicalDisk = 33,
/// <summary>
/// 逻辑磁盘所在分区及始末位置
/// </summary>
LogicalDiskToPartition = 34,
/// <summary>
/// 逻辑内存配置
/// </summary>
LogicalMemoryConfiguration = 35,
/// <summary>
/// 系统页文件信息
/// </summary>
PageFile = 36,
/// <summary>
/// 页文件设置
/// </summary>
PageFileSetting = 37,
/// <summary>
/// 系统启动配置
/// </summary>
BootConfiguration = 38,
/// <summary>
/// 计算机信息简要
/// </summary>
ComputerSystem = 39,
/// <summary>
/// 操作系统信息
/// </summary>
OperatingSystem = 40,
/// <summary>
/// 系统自动启动程序
/// </summary>
StartupCommand = 41,
/// <summary>
/// 系统安装的服务
/// </summary>
Service = 42,
/// <summary>
/// 系统管理组
/// </summary>
Group = 43,
/// <summary>
/// 系统组帐号
/// </summary>
GroupUser = 44,
/// <summary>
/// 用户帐号
/// </summary>
UserAccount = 45,
/// <summary>
/// 系统进程
/// </summary>
Process = 46,
/// <summary>
/// 系统线程
/// </summary>
Thread = 47,
/// <summary>
/// 共享
/// </summary>
Share = 48,
/// <summary>
/// 已安装的网络客户端
/// </summary>
NetworkClient = 49,
/// <summary>
/// 已安装的网络协议
/// </summary>
NetworkProtocol = 50,
/// <summary>
/// all device 所有设备
/// </summary>
PnPEntity = 51,
/*
Win32_1394Controller
Win32_1394ControllerDevice
Win32_Account
Win32_AccountSID
Win32_ACE
Win32_ActionCheck
Win32_AllocatedResource
Win32_ApplicationCommandLine
Win32_ApplicationService
Win32_AssociatedBattery
Win32_AssociatedProcessorMemory
Win32_BaseBoard
Win32_BaseService
Win32_Battery
Win32_Binary
Win32_BindImageAction
Win32_BIOS
Win32_BootConfiguration
Win32_Bus
Win32_CacheMemory
Win32_CDROMDrive
Win32_CheckCheck
Win32_CIMLogicalDeviceCIMDataFile
Win32_ClassicCOMApplicationClasses
Win32_ClassicCOMClass
Win32_ClassicCOMClassSetting
Win32_ClassicCOMClassSettings
Win32_ClassInfoAction
Win32_ClientApplicationSetting
Win32_CodecFile
Win32_COMApplication
Win32_COMApplicationClasses
Win32_COMApplicationSettings
Win32_COMClass
Win32_ComClassAutoEmulator
Win32_ComClassEmulator
Win32_CommandLineAccess
Win32_ComponentCategory
Win32_ComputerSystem
Win32_ComputerSystemProcessor
Win32_ComputerSystemProduct
Win32_COMSetting
Win32_Condition
Win32_CreateFolderAction
Win32_CurrentProbe
Win32_DCOMApplication
Win32_DCOMApplicationAccessAllowedSetting
Win32_DCOMApplicationLaunchAllowedSetting
Win32_DCOMApplicationSetting
Win32_DependentService
Win32_Desktop
Win32_DesktopMonitor
Win32_DeviceBus
Win32_DeviceMemoryAddress
Win32_DeviceSettings
Win32_Directory
Win32_DirectorySpecification
Win32_DiskDrive
Win32_DiskDriveToDiskPartition
Win32_DiskPartition
Win32_DisplayConfiguration
Win32_DisplayControllerConfiguration
Win32_DMAChannel
Win32_DriverVXD
Win32_DuplicateFileAction
Win32_Environment
Win32_EnvironmentSpecification
Win32_ExtensionInfoAction
Win32_Fan
Win32_FileSpecification
Win32_FloppyController
Win32_FloppyDrive
Win32_FontInfoAction
Win32_Group
Win32_GroupUser
Win32_HeatPipe
Win32_IDEController
Win32_IDEControllerDevice
Win32_ImplementedCategory
Win32_InfraredDevice
Win32_IniFileSpecification
Win32_InstalledSoftwareElement
Win32_IRQResource
Win32_Keyboard
Win32_LaunchCondition
Win32_LoadOrderGroup
Win32_LoadOrderGroupServiceDependencies
Win32_LoadOrderGroupServiceMembers
Win32_LogicalDisk
Win32_LogicalDiskRootDirectory
Win32_LogicalDiskToPartition
Win32_LogicalFileAccess
Win32_LogicalFileAuditing
Win32_LogicalFileGroup
Win32_LogicalFileOwner
Win32_LogicalFileSecuritySetting
Win32_LogicalMemoryConfiguration
Win32_LogicalProgramGroup
Win32_LogicalProgramGroupDirectory
Win32_LogicalProgramGroupItem
Win32_LogicalProgramGroupItemDataFile
Win32_LogicalShareAccess
Win32_LogicalShareAuditing
Win32_LogicalShareSecuritySetting
Win32_ManagedSystemElementResource
Win32_MemoryArray
Win32_MemoryArrayLocation
Win32_MemoryDevice
Win32_MemoryDeviceArray
Win32_MemoryDeviceLocation
Win32_MethodParameterClass
Win32_MIMEInfoAction
Win32_MotherboardDevice
Win32_MoveFileAction
Win32_MSIResource
Win32_NetworkAdapter
Win32_NetworkAdapterConfiguration
Win32_NetworkAdapterSetting
Win32_NetworkClient
Win32_NetworkConnection
Win32_NetworkLoginProfile
Win32_NetworkProtocol
Win32_NTEventlogFile
Win32_NTLogEvent
Win32_NTLogEventComputer
Win32_NTLogEventLog
Win32_NTLogEventUser
Win32_ODBCAttribute
Win32_ODBCDataSourceAttribute
Win32_ODBCDataSourceSpecification
Win32_ODBCDriverAttribute
Win32_ODBCDriverSoftwareElement
Win32_ODBCDriverSpecification
Win32_ODBCSourceAttribute
Win32_ODBCTranslatorSpecification
Win32_OnBoardDevice
Win32_OperatingSystem
Win32_OperatingSystemQFE
Win32_OSRecoveryConfiguration
Win32_PageFile
Win32_PageFileElementSetting
Win32_PageFileSetting
Win32_PageFileUsage
Win32_ParallelPort
Win32_Patch
Win32_PatchFile
Win32_PatchPackage
Win32_PCMCIAController
Win32_Perf
Win32_PerfRawData
Win32_PerfRawData_ASP_ActiveServerPages
Win32_PerfRawData_ASPNET_114322_ASPNETAppsv114322
Win32_PerfRawData_ASPNET_114322_ASPNETv114322
Win32_PerfRawData_ASPNET_ASPNET
Win32_PerfRawData_ASPNET_ASPNETApplications
Win32_PerfRawData_IAS_IASAccountingClients
Win32_PerfRawData_IAS_IASAccountingServer
Win32_PerfRawData_IAS_IASAuthenticationClients
Win32_PerfRawData_IAS_IASAuthenticationServer
Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal
Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator
Win32_PerfRawData_MSFTPSVC_FTPService
Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods
Win32_PerfRawData_MSSQLSERVER_SQLServerBackupDevice
Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager
Win32_PerfRawData_MSSQLSERVER_SQLServerBufferPartition
Win32_PerfRawData_MSSQLSERVER_SQLServerCacheManager
Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases
Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics
Win32_PerfRawData_MSSQLSERVER_SQLServerLatches
Win32_PerfRawData_MSSQLSERVER_SQLServerLocks
Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationAgents
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationDist
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationLogreader
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationMerge
Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationSnapshot
Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics
Win32_PerfRawData_MSSQLSERVER_SQLServerUserSettable
Win32_PerfRawData_NETFramework_NETCLRExceptions
Win32_PerfRawData_NETFramework_NETCLRInterop
Win32_PerfRawData_NETFramework_NETCLRJit
Win32_PerfRawData_NETFramework_NETCLRLoading
Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
Win32_PerfRawData_NETFramework_NETCLRMemory
Win32_PerfRawData_NETFramework_NETCLRRemoting
Win32_PerfRawData_NETFramework_NETCLRSecurity
Win32_PerfRawData_Outlook_Outlook
Win32_PerfRawData_PerfDisk_PhysicalDisk
Win32_PerfRawData_PerfNet_Browser
Win32_PerfRawData_PerfNet_Redirector
Win32_PerfRawData_PerfNet_Server
Win32_PerfRawData_PerfNet_ServerWorkQueues
Win32_PerfRawData_PerfOS_Cache
Win32_PerfRawData_PerfOS_Memory
Win32_PerfRawData_PerfOS_Objects
Win32_PerfRawData_PerfOS_PagingFile
Win32_PerfRawData_PerfOS_Processor
Win32_PerfRawData_PerfOS_System
Win32_PerfRawData_PerfProc_FullImage_Costly
Win32_PerfRawData_PerfProc_Image_Costly
Win32_PerfRawData_PerfProc_JobObject
Win32_PerfRawData_PerfProc_JobObjectDetails
Win32_PerfRawData_PerfProc_Process
Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly
Win32_PerfRawData_PerfProc_Thread
Win32_PerfRawData_PerfProc_ThreadDetails_Costly
Win32_PerfRawData_RemoteAccess_RASPort
Win32_PerfRawData_RemoteAccess_RASTotal
Win32_PerfRawData_RSVP_ACSPerRSVPService
Win32_PerfRawData_Spooler_PrintQueue
Win32_PerfRawData_TapiSrv_Telephony
Win32_PerfRawData_Tcpip_ICMP
Win32_PerfRawData_Tcpip_IP
Win32_PerfRawData_Tcpip_NBTConnection
Win32_PerfRawData_Tcpip_NetworkInterface
Win32_PerfRawData_Tcpip_TCP
Win32_PerfRawData_Tcpip_UDP
Win32_PerfRawData_W3SVC_WebService
Win32_PhysicalMemory
Win32_PhysicalMemoryArray
Win32_PhysicalMemoryLocation
Win32_PNPAllocatedResource
Win32_PnPDevice
Win32_PnPEntity
Win32_PointingDevice
Win32_PortableBattery
Win32_PortConnector
Win32_PortResource
Win32_POTSModem
Win32_POTSModemToSerialPort
Win32_PowerManagementEvent
Win32_Printer
Win32_PrinterConfiguration
Win32_PrinterController
Win32_PrinterDriverDll
Win32_PrinterSetting
Win32_PrinterShare
Win32_PrintJob
Win32_PrivilegesStatus
Win32_Process
Win32_Processor
Win32_ProcessStartup
Win32_Product
Win32_ProductCheck
Win32_ProductResource
Win32_ProductSoftwareFeatures
Win32_ProgIDSpecification
Win32_ProgramGroup
Win32_ProgramGroupContents
Win32_ProgramGroupOrItem
Win32_Property
Win32_ProtocolBinding
Win32_PublishComponentAction
Win32_QuickFixEngineering
Win32_Refrigeration
Win32_Registry
Win32_RegistryAction
Win32_RemoveFileAction
Win32_RemoveIniAction
Win32_ReserveCost
Win32_ScheduledJob
Win32_SCSIController
Win32_SCSIControllerDevice
Win32_SecurityDescriptor
Win32_SecuritySetting
Win32_SecuritySettingAccess
Win32_SecuritySettingAuditing
Win32_SecuritySettingGroup
Win32_SecuritySettingOfLogicalFile
Win32_SecuritySettingOfLogicalShare
Win32_SecuritySettingOfObject
Win32_SecuritySettingOwner
Win32_SelfRegModuleAction
Win32_SerialPort
Win32_SerialPortConfiguration
Win32_SerialPortSetting
Win32_Service
Win32_ServiceControl
Win32_ServiceSpecification
Win32_ServiceSpecificationService
Win32_SettingCheck
Win32_Share
Win32_ShareToDirectory
Win32_ShortcutAction
Win32_ShortcutFile
Win32_ShortcutSAP
Win32_SID
Win32_SMBIOSMemory
Win32_SoftwareElement
Win32_SoftwareElementAction
Win32_SoftwareElementCheck
Win32_SoftwareElementCondition
Win32_SoftwareElementResource
Win32_SoftwareFeature
Win32_SoftwareFeatureAction
Win32_SoftwareFeatureCheck
Win32_SoftwareFeatureParent
Win32_SoftwareFeatureSoftwareElements
Win32_SoundDevice
Win32_StartupCommand
Win32_SubDirectory
Win32_SystemAccount
Win32_SystemBIOS
Win32_SystemBootConfiguration
Win32_SystemDesktop
Win32_SystemDevices
Win32_SystemDriver
Win32_SystemDriverPNPEntity
Win32_SystemEnclosure
Win32_SystemLoadOrderGroups
Win32_SystemLogicalMemoryConfiguration
Win32_SystemMemoryResource
Win32_SystemNetworkConnections
Win32_SystemOperatingSystem
Win32_SystemPartitions
Win32_SystemProcesses
Win32_SystemProgramGroups
Win32_SystemResources
Win32_SystemServices
Win32_SystemSetting
Win32_SystemSlot
Win32_SystemSystemDriver
Win32_SystemTimeZone
Win32_SystemUsers
Win32_TapeDrive
Win32_TemperatureProbe
Win32_Thread
Win32_TimeZone
Win32_Trustee
Win32_TypeLibraryAction
Win32_UninterruptiblePowerSupply
Win32_USBController
Win32_USBControllerDevice
Win32_UserAccount
Win32_UserDesktop
Win32_VideoConfiguration
Win32_VideoController
Win32_VideoSettings
Win32_VoltageProbe
Win32_WMIElementSetting
Win32_WMISetting
*/
}
/// <summary>
/// 获取硬件及系统详细信息
/// </summary>
/// <param name="DeviceType">硬件名称或系统名称</param>
/// <returns></returns>
public static string GetHardwareInfo(HardWareType DeviceType)
{
string vs = "";
switch (DeviceType)
{
case HardWareType.CPU:
vs = DisplayDeviceMessage("Win32_Processor");
break;
case HardWareType.ComputerSystem:
vs = DisplayDeviceMessage("Win32_ComputerSystem");
break;
case HardWareType.PhysicalMemory:
vs = DisplayDeviceMessage("Win32_PointingDevice");
break;
case HardWareType.Keyboard :
vs = DisplayDeviceMessage("Win32_Keyboard");
break;
case HardWareType.PointingDevice :
vs = DisplayDeviceMessage("Win32_PointingDevice");
break;
case HardWareType.FloppyDrive :
vs = DisplayDeviceMessage("Win32_FloppyDrive");
break;
case HardWareType.DiskDrive :
vs = DisplayDeviceMessage("Win32_DiskDrive");
break;
case HardWareType.CDROMDrive:
vs = DisplayDeviceMessage("Win32_CDROMDrive");
break;
case HardWareType.BaseBoard:
vs = DisplayDeviceMessage("Win32_BaseBoard");
break;
case HardWareType.BIOS:
vs = DisplayDeviceMessage("Win32_BIOS");
break;
case HardWareType.ParallelPort:
vs = DisplayDeviceMessage("Win32_ParallelPort");
break;
case HardWareType.SerialPort:
vs = DisplayDeviceMessage("Win32_SerialPort");
break;
case HardWareType.SerialPortConfiguration:
vs = DisplayDeviceMessage("Win32_SerialPortConfiguration");
break;
case HardWareType.SoundDevice:
vs = DisplayDeviceMessage("Win32_SoundDevice");
break;
case HardWareType.SystemSlot:
vs = DisplayDeviceMessage("Win32_SystemSlot");
break;
case HardWareType.USBController:
vs = DisplayDeviceMessage("Win32_USBController");
break;
case HardWareType.NetworkAdapter:
vs = DisplayDeviceMessage("Win32_NetworkAdapter");
break;
case HardWareType.NetworkAdapterConfiguration:
vs = DisplayDeviceMessage("Win32_NetworkAdapterConfiguration");
break;
case HardWareType.Printer:
vs = DisplayDeviceMessage("Win32_Printer");
break;
case HardWareType.PrinterConfiguration:
vs = DisplayDeviceMessage("Win32_PrinterConfiguration");
break;
case HardWareType.PrintJob:
vs = DisplayDeviceMessage("Win32_PrintJob");
break;
case HardWareType.TCPIPPrinterPort:
vs = DisplayDeviceMessage("Win32_TCPIPPrinterPort");
break;
case HardWareType.POTSModem:
vs = DisplayDeviceMessage("Win32_POTSModem");
break;
case HardWareType.POTSModemToSerialPort:
vs = DisplayDeviceMessage("Win32_POTSModemToSerialPort");
break;
case HardWareType.DesktopMonitor:
vs = DisplayDeviceMessage("Win32_DesktopMonitor");
break;
case HardWareType.DisplayConfiguration:
vs = DisplayDeviceMessage("Win32_DisplayConfiguration");
break;
case HardWareType.DisplayControllerConfiguration:
vs = DisplayDeviceMessage("Win32_DisplayControllerConfiguration");
break;
case HardWareType.VideoController:
vs = DisplayDeviceMessage("Win32_VideoController");
break;
case HardWareType.VideoSettings:
vs = DisplayDeviceMessage("Win32_VideoSettings");
break;
case HardWareType.TimeZone :
vs = DisplayDeviceMessage("Win32_TimeZone");
break;
case HardWareType.SystemDriver:
vs = DisplayDeviceMessage("Win32_SystemDriver");
break;
case HardWareType.DiskPartition:
vs = DisplayDeviceMessage("Win32_DiskPartition");
break;
case HardWareType.LogicalDisk:
vs = DisplayDeviceMessage("Win32_LogicalDisk");
break;
case HardWareType.LogicalDiskToPartition :
vs = DisplayDeviceMessage("Win32_LogicalDiskToPartition");
break;
case HardWareType.LogicalMemoryConfiguration :
vs = DisplayDeviceMessage("Win32_LogicalMemoryConfiguration");
break;
case HardWareType.PageFile:
vs = DisplayDeviceMessage("Win32_PageFile");
break;
case HardWareType.PageFileSetting:
vs = DisplayDeviceMessage("Win32_PageFileSetting");
break;
case HardWareType.BootConfiguration:
vs = DisplayDeviceMessage("Win32_BootConfiguration");
break;
case HardWareType.OperatingSystem:
vs = DisplayDeviceMessage("Win32_OperatingSystem");
break;
case HardWareType.StartupCommand:
vs = DisplayDeviceMessage("Win32_StartupCommand");
break;
case HardWareType.Service :
vs = DisplayDeviceMessage("Win32_Service");
break;
case HardWareType.Group :
vs = DisplayDeviceMessage("Win32_Group");
break;
case HardWareType.GroupUser :
vs = DisplayDeviceMessage("Win32_GroupUser");
break;
case HardWareType.UserAccount:
vs = DisplayDeviceMessage("Win32_UserAccount");
break;
case HardWareType.Process :
vs = DisplayDeviceMessage("Win32_Process");
break;
case HardWareType.Thread :
vs = DisplayDeviceMessage("Win32_Thread");
break;
case HardWareType.Share :
vs = DisplayDeviceMessage("Win32_Share");
break;
case HardWareType.NetworkClient :
vs = DisplayDeviceMessage("Win32_NetworkClient");
break;
case HardWareType.NetworkProtocol:
vs = DisplayDeviceMessage("Win32_NetworkProtocol");
break;
case HardWareType.PnPEntity :
vs = DisplayDeviceMessage("Win32_PnPEntity");
break;
}
return vs;
}
/// <summary>
/// 获取硬件及系统详细信息
/// </summary>
/// <param name="queryKey">Win32_Processor</param>
/// <returns></returns>
public static string GetHardwareInfo(string queryKey)
{
return DisplayDeviceMessage(queryKey);
}
/// <summary>
/// 获取CUPID
/// </summary>
/// <returns></returns>
public static string Get_CPU_ID()
{
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
string strID = null;
foreach (ManagementObject mo in moc)
{
strID = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return strID;
}
/// <summary>
/// 浏览器客户端 获取网卡MAC地址MD5加密串 杨旭东
/// </summary>
/// <returns></returns>
public static string GetClientMac()
{
try
{
string clientIP = System.Web.HttpContext.Current.Request.UserHostAddress.Trim();
Int32 idest = API.inet_addr(clientIP);
Int64 macInfo = new Int64();
Int32 length = 6;
int res = API.SendARP(idest, 0, ref macInfo, ref length);
string mac_src = macInfo.ToString("X");
if (!string.IsNullOrEmpty(mac_src) && !"0".Equals(mac_src))
{
while (mac_src.Length < 12)
{
mac_src = mac_src.Insert(0, "0");
}
string mac_dest = string.Empty;
for (int i = 0; i < 11; i++)
{
if (i % 2 == 0)
{
if (i == 10)
mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2));
else
mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2));
}
}
return mac_dest;
}
}
catch
{
return "";
}
return "";
}
///// <summary>
///// 获取CPU序列号代码
///// </summary>
///// <returns></returns>
//public static string GetCpuID()
//{
// try
// {
// //获取CPU序列号代码
// string cpuInfo = "";//cpu序列号
// ManagementClass mc = new ManagementClass("Win32_Processor");
// ManagementObjectCollection moc = mc.GetInstances();
// foreach (ManagementObject mo in moc)
// {
// cpuInfo += mo.Properties["ProcessorId"].Value.ToString() + ",";
// }
// moc = null;
// mc = null;
// if (cpuInfo.Length > 0) cpuInfo = cpuInfo.Substring(0, cpuInfo.Length - 1);
// return cpuInfo;
// }
// catch
// {
// return "unknow";
// }
// finally
// {
// }
//}
/// <summary>
/// 获取主板ID
/// </summary>
/// <returns></returns>
public static string GetMainboardID()
{
ManagementClass mc = new ManagementClass("Win32_BaseBoard");
ManagementObjectCollection moc = mc.GetInstances();
string strID = "";
foreach (ManagementObject mo in moc)
{
strID += mo.Properties["SerialNumber"].Value.ToString() + ",";
}
if (strID.Length > 0) strID = strID.Substring(0, strID.Length - 1);
return strID;
}
/// <summary>
/// 获取硬盘ID
/// </summary>
/// <returns></returns>
public static string GetDiskID()
{
ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
//网上有提到,用Win32_DiskDrive,但是用Win32_DiskDrive获得的硬盘信息中并不包含SerialNumber属性。
ManagementObjectCollection moc = mc.GetInstances();
string strID = null;
foreach (ManagementObject mo in moc)
{
try
{
string sTemp = mo.ToString();
strID += mo.Properties["SerialNumber"].Value.ToString() + ",";
}
catch { }
}
if (strID.Length > 0) strID = strID.Substring(0, strID.Length - 1);
return strID;
}
/// <summary>
/// 获取BIOS编号
/// </summary>
/// <returns></returns>
public static string GetBIOSID()
{
ManagementClass mc = new ManagementClass("Win32_BIOS");
ManagementObjectCollection moc = mc.GetInstances();
string strID = "";
foreach (ManagementObject mo in moc)
{
strID = mo.Properties["SerialNumber"].Value.ToString();
}
if (strID.Length > 0) strID = strID.Substring(0, strID.Length - 1);
return strID;
}
/// <summary>
/// 设置ip地址
/// </summary>
/// <param name="ipAddress">IP地址</param>
/// <param name="subnetMask">子网掩码</param>
/// <param name="gateway">网关</param>
public static void SetNetworkAdapter(string ipAddress, string subnetMask, string gateway)
{
IPAddress ethernetIPAddress = GetEthernetIPAddress();
ManagementBaseObject inPar = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (!(bool)mo["IPEnabled"])
continue;
if (((string[])mo["IPAddress"])[0] == ethernetIPAddress.ToString())
{
inPar = mo.GetMethodParameters("EnableStatic");
//设置ip地址和子网掩码
inPar["IPAddress"] = new string[] { ipAddress };
inPar["SubnetMask"] = new string[] { subnetMask };
mo.InvokeMethod("EnableStatic", inPar, null);
//设置网关地址
if (gateway != null)
{
inPar = mo.GetMethodParameters("SetGateways");
inPar["DefaultIPGateway"] = new string[] { gateway };
mo.InvokeMethod("SetGateways", inPar, null);
}
break;
}
}
}
/// <summary>
/// 查找以太网ip
/// </summary>
/// <returns></returns>
public static IPAddress GetEthernetIPAddress()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
if (adapter.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
{
foreach (var item in adapter.GetIPProperties().UnicastAddresses)
{
if (item.Address.AddressFamily == AddressFamily.InterNetwork)
return item.Address; //item.IPv4Mask获取掩码
}
}
}
return null;
//throw new Exception("Ethernet not connected");
}
/// <summary>
/// 获取网卡物理地址 MAC
/// </summary>
/// <returns></returns>
public static string getMacAddr_Local()
{
string madAddr = null;
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc2 = mc.GetInstances();
foreach (ManagementObject mo in moc2)
{
if (Convert.ToBoolean(mo["IPEnabled"]) == true)
{
madAddr = mo["MacAddress"].ToString();
madAddr = madAddr.Replace(':', '-');
}
mo.Dispose();
}
return madAddr;
}
/// <summary>
/// 获取IP地址(IPv4)
/// </summary>
/// <returns></returns>
public static string GetIPAddress()
{
try
{
IPAddress[] arrIPAddresses = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress ip in arrIPAddresses)
{
if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))//IPv4
{
return ip.ToString();
}
}
return "";
}
catch
{
return "";
}
finally
{
}
}
///<summary>
///操作系统的登录用户名
///</summary>
///<returns></returns>
public static string GetUserName()
{
try
{
byte[] userName = new byte[30];
Int32[] length = new Int32[1];
length[0] = 30;//限定用户名长度
API.GetUserName(userName, length);
return System.Text.Encoding.ASCII.GetString(userName);
}
catch
{
return "";
}
finally
{
}
}
///<summary>
/// PC类型
///</summary>
///<returns></returns>
public static string GetSystemType()
{
try
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["SystemType"].ToString();
}
moc = null;
mc = null;
return st;
}
catch
{
return "";
}
finally
{
}
}
///<summary>
///物理内存
///</summary>
///<returns></returns>
public static string GetTotalPhysicalMemory()
{
try
{
API.MEMORY_INFO memoryInfo = new API.MEMORY_INFO();
API.GlobalMemoryStatus(ref memoryInfo);
return memoryInfo.dwTotalPhys.ToString();
}
catch
{
return "";
}
finally
{
}
}
///<summary>
/// 获取计算机名称
///</summary>
///<returns></returns>
public static string GetComputerName()
{
try
{
byte[] computerName = new byte[30];
Int32[] length = new Int32[1];
length[0] = 30;//限定计算机名长度
API.GetComputerName(computerName, length);
return System.Text.Encoding.ASCII.GetString(computerName);
}
catch
{
return "";
}
finally
{
}
}
/// <summary>
///
/// </summary>
/// <param name="drvID"></param>
/// <returns></returns>
public static string GetVolOf(string drvID)
{
const int MAX_FILENAME_LEN = 6;
int retVal = 0;
int a = 0;
int b = 0;
string str = null;
int i = API.GetVolumeInformation(
drvID + @":\",
str,
MAX_FILENAME_LEN,
ref retVal,
a,
b,
str,
MAX_FILENAME_LEN
);
return retVal.ToString("x");
}
private static string DisplayDeviceMessage(string queryKey)
{
//rtxtDisplay.Clear();
StringBuilder sb = new StringBuilder();
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM " + queryKey);
ManagementObjectCollection managementObjectCollection = searcher.Get();
//DisplayMessage($"【{queryKey}】设备信息个数:{managementObjectCollection.Count}");
try
{
sb.Append("设备信息个数:" + managementObjectCollection.Count + " \n");
}
catch
{
return "";
}
foreach (ManagementObject managementObject in managementObjectCollection)
{
//DisplayMessage($"管理对象的属性个数:{managementObject.Properties.Count}");
sb.Append("管理对象的属性个数:" + managementObject.Properties.Count + " \n");
foreach (PropertyData propertyData in managementObject.Properties)
{
List<string> listQualifier = new List<string>();
foreach (QualifierData qualifierData in propertyData.Qualifiers)
{
//listQualifier.Add($"[{qualifierData.Name}:{qualifierData.Value}]");
listQualifier .Add (qualifierData.Name.ToString() + ":" + qualifierData.Value.ToString());
}
//sb.Append($" {propertyData.Name}:{propertyData.Value}--类型:【{propertyData.Type}】,限定符集合:【{string.Join(",", listQualifier)}】\n");
//string js = string.Join(",", listQualifier);
sb.Append(propertyData.Name.ToString() + ":" + (propertyData.Value == null ? "" : propertyData.Value.ToString()) + " 类型:" + propertyData.Type + " 限定符集合:" + string.Join(",",StringHelper.GetListToStringArray (listQualifier)) + " \n");
}
//DisplayMessage(sb.ToString());
//DisplayMessage($"管理对象的系统属性个数:{managementObject.SystemProperties.Count}");
//sb = new StringBuilder();
sb.Append("管理对象的系统属性个数:" + managementObject.SystemProperties.Count + " \n");
foreach (PropertyData propertyData in managementObject.SystemProperties)
{
List<string> listQualifier = new List<string>();
foreach (QualifierData qualifierData in propertyData.Qualifiers)
{
//listQualifier.Add($"[{qualifierData.Name}:{qualifierData.Value}]");
listQualifier.Add(qualifierData.Name.ToString() + ":" + qualifierData.Value.ToString());
}
sb.Append(propertyData.Name.ToString() + ":" + (propertyData.Value == null ? "" : propertyData.Value.ToString()) + " 类型:" + propertyData.Type + " 限定符集合:" + string.Join(",", StringHelper.GetListToStringArray(listQualifier)) + " \n");
}
}
return sb.ToString();
}
/// <summary>
/// 10进制数 转换成 16进制 转换十六进制字符串并交换数字
/// 如: 4833395344463658202020202020202020202020 转换成 WD-WMAJD1092385
/// </summary>
/// <param name="hex"></param>
/// <returns></returns>
public static string ConvertAndSwapHex(string hex)
{
hex = hex.Replace("-", "");
byte[] raw = new byte[hex.Length / 2];
for (int i = 0; i < raw.Length; i++)
{
int j = i;
if (j != 0)
{
j = (j % 2 == 1 ? j - 1 : j + 1);
}
raw[j] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
}
return System.Text.Encoding.UTF8.GetString(raw).Trim(' ', '\t', '\0');
}
/// <summary>
/// 10进制数 转换成 16进制 转换十六进制字符串并交换数字
/// 如: 4833395344463658202020202020202020202020 转换成 WD-WMAJD1092385
/// </summary>
/// <param name="hexString"></param>
/// <returns></returns>
public static string ConvertAndSwapHexR(string hexString)
{
var charString = new StringBuilder();
for (var i = 0; i < hexString.Length; i += 4)
{
charString.Append(Convert.ToChar(Convert.ToUInt32(hexString.Substring(i + 2, 2), 16)));
charString.Append(Convert.ToChar(Convert.ToUInt32(hexString.Substring(i, 2), 16)));
}
return charString.ToString ().Trim(' ', '\t', '\0');
}
}
public class SystemRunEvnInfo
{
//[Display(Name = "机器名称")]
/// <summary>
/// 返回机器名称
/// </summary>
public string MachineName { get { return Environment.MachineName; } }
//[Display(Name = "用户网络域名")]
/// <summary>
/// 返回用户网络域名
/// </summary>
public string UserDomainName { get { return Environment.UserDomainName; } }
//[Display(Name = "分区磁盘")]
/// <summary>
/// 分区磁盘
/// </summary>
public string GetLogicalDrives { get { return string.Join(", ", Environment.GetLogicalDrives()); } }
//[Display(Name = "系统目录")]
/// <summary>
/// 系统目录
/// </summary>
public string SystemDirectory { get { return Environment.SystemDirectory; } }
//[Display(Name = "系统已运行时间(毫秒)")]
/// <summary>
/// 系统已运行时间(毫秒)
/// </summary>
public int TickCount { get { return Environment.TickCount; } }
//[Display(Name = "是否在交互模式中运行")]
/// <summary>
/// 是否在交互模式中运行
/// </summary>
public bool UserInteractive { get { return Environment.UserInteractive; } }
//[Display(Name = "当前关联用户名")]
/// <summary>
/// 当前关联用户名
/// </summary>
public string UserName { get { return Environment.UserName; } }
//[Display(Name = "Web程序核心框架版本")]
/// <summary>
/// 远行框架 获取本机.net framework 版本信息
/// </summary>
public string Version { get { return Environment.Version.ToString(); } }
/// <summary>
/// 操作系统版本
/// </summary>
public string OSVersion { get { return Environment.OSVersion.ToString(); } }
//对Linux无效
//[Display(Name = "磁盘分区")]
/// <summary>
/// 系统盘
/// </summary>
public string SystemDrive { get { return Environment.ExpandEnvironmentVariables("%SystemDrive%"); } }
//对Linux无效
//[Display(Name = "系统目录")]
/// <summary>
/// 系统目录
/// </summary>
public string SystemRoot { get { return Environment.ExpandEnvironmentVariables("%SystemRoot%"); } }
/// <summary>
/// 程序目录
/// </summary>
public string SoftDirectory { get { return Environment.CurrentDirectory.ToString(); } }
/// <summary>
/// 物理内存
/// </summary>
public string PhysicalMemory { get { return Environment.WorkingSet.ToString(); } }
/// <summary>
/// 从当前进程检索环境变量的值。
/// </summary>
public string EnvironmentVariable { get { System.Collections.IDictionary dict = Environment.GetEnvironmentVariables(); return dict["Path"].ToString(); } }
/// <summary>
/// 返回处理器的个数
/// </summary>
public int ProcessorCount { get { return Environment.ProcessorCount; } }
/// <summary>
/// 进程已使用物理内存(KB)
/// </summary>
public double ProcessMemory { get { return Convert.ToDouble ( Process.GetCurrentProcess().WorkingSet64 / 1024.0) ; } }
/// <summary>
/// 进程已占耗CPU时间(ms)
/// </summary>
public double ProcessTime { get { return Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds ; } }
/// <summary>
/// 设置环境变量
/// </summary>
/// <returns></returns>
public void SetEnvironmentVariable(string variable, string value)
{
Environment.SetEnvironmentVariable(variable, value);
}
}
public static class DemoHardware
{
//string JsonStr;
//硬件信息
//JsonStr = HardwareInformation.GetJsonStr();
//var ObjHardware = JsonSerializer.Deserialize<Dictionary<string, object>>(JsonStr);
//ListBox listbox1 = tabControl1.TabPages[0].Controls["listbox1"] as ListBox;
//listbox1.Items.Add("主板:"+ ObjHardware["MainboardName"]);
//listbox1.Items.Add("内存:" + ObjHardware["MemorySize"]);
//listbox1.Items.Add("硬盘:" + ObjHardware["HarddiskSize"]);
//listbox1.Items.Add("显卡:" + ObjHardware["VideocardName"]);
//listbox1.Items.Add("声卡:" + ObjHardware["SoundcardName"]);
//listbox1.Items.Add("网卡:" + ObjHardware["NetworkcardName"]);
//listbox1.Items.Add("计算机生产商:" + ObjHardware["ManufacturerName"]);
//listbox1.Items.Add("计算机生产日期:" + ObjHardware["ManufactureDate"]);
public static void test()
{
//string JsonStr;
//JsonStr = HardwareInformation.GetJsonStr();
//var ObjHardware = JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonStr);
//System.Collections.ArrayList list = new System.Collections.ArrayList();
//list.Add("主板:" + ObjHardware["MainboardName"]);
//list.Add("主板:" + ObjHardware["MainboardName"]);
//list.Add("内存:" + ObjHardware["MemorySize"]);
//list.Add("硬盘:" + ObjHardware["HarddiskSize"]);
//list.Add("显卡:" + ObjHardware["VideocardName"]);
//list.Add("声卡:" + ObjHardware["SoundcardName"]);
//list.Add("网卡:" + ObjHardware["NetworkcardName"]);
//list.Add("计算机生产商:" + ObjHardware["ManufacturerName"]);
//list.Add("计算机生产日期:" + ObjHardware["ManufactureDate"]);
}
}
标签:Win32,string,DisplayDeviceMessage,HardWareType,硬件,获取,PerfRawData,vs,详细信息
From: https://blog.51cto.com/u_3343848/7136308