C#獲取當前主機硬體信息

来源:http://www.cnblogs.com/xcjit/archive/2017/04/22/6747767.html
-Advertisement-
Play Games

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; using System.Net;using System.Manageme ...


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


using System.Net;
using System.Management;  //在項目-》添加引用....裡面引用System.Management
using System.Runtime.InteropServices;


namespace FileSplit
{
//此類用於獲取當前主機的相關信息
public class MachineInfo
{
//用法示例
private string example()
{
string Info = "";
MachineInfo info = MachineInfo.I(); //獲取主機的對象信息


Info = "\r\n主機名:" + Dns.GetHostName(); //獲取主機名稱
Info += "\r\n系統類型:" + info.GetSystemType();
Info += "\r\n物理記憶體:" + info.GetPhysicalMemory();


Info += "\r\n\r\n本地IP:";
string[] LocalIp = info.GetLocalIpAddress();
foreach (string ip in LocalIp) Info += "\r\n" + ip;


Info += "\r\n\r\n外網IP:";
string[] ExternalIp = info.GetExtenalIpAddress();
foreach (string ip in ExternalIp) Info += "\r\n" + ip;


Info += "\r\n\r\nMAC:";
Info += "\r\n" + info.GetNetCardMACAddress();
//Info += "\r\n" + info.GetMacAddress(LocalIp[0]);


Info += "\r\n";
Info += "\r\nCPU序列號:" + info.GetCPUSerialNumber();
//Info += "\r\nCPU編號:" + info.GetCPUID();
//Info += "\r\nCPU版本信息:" + info.GetCPUVersion();
//Info += "\r\nCPU名稱信息:" + info.GetCPUName();
//Info += "\r\nCPU製造廠商:" + info.GetCPUManufacturer();
//Info += "\r\n主板製造廠商:" + info.GetBoardManufacturer();


//Info += "\r\n主板序列號:" + info.GetBIOSSerialNumber();
//Info += "\r\n硬碟序列號:" + info.GetHardDiskSerialNumber();
//Info += "\r\n顯卡PNPDeviceID:\r\n" + info.GetVideoPNPID();
//Info += "\r\n音效卡PNPDeviceID:\r\n" + info.GetSoundPNPID();


return Info;
}

 


static MachineInfo Instance;


/// <summary>
/// 獲取當前類對象的一個實例
/// </summary>
public static MachineInfo I()
{
if (Instance == null) Instance = new MachineInfo();
return Instance;
}

/// <summary>
/// 獲取本地ip地址,多個ip
/// </summary>
public String[] GetLocalIpAddress()
{
string hostName = Dns.GetHostName(); //獲取主機名稱
IPAddress[] addresses = Dns.GetHostAddresses(hostName); //解析主機IP地址


string[] IP = new string[addresses.Length]; //轉換為字元串形式
for (int i = 0; i < addresses.Length; i++) IP[i] = addresses[i].ToString();


return IP;
}

 


//從網站"http://1111.ip138.com/ic.asp",獲取本機外網ip地址信息串
//"<html>\r\n<head>\r\n<meta http-equiv=\"content-type\" content=\"text/html; charset=gb2312\">\r\n<title>
//您的IP地址 </title>\r\n</head>\r\n<body style=\"margin:0px\"><center>您的IP是:[218.104.71.178] 來自:安徽省合肥市 聯通</center></body></html>"


/// <summary>
/// 獲取外網ip地址
/// </summary>
public string[] GetExtenalIpAddress()
{
string[] IP = new string[] { "未獲取到外網ip", "" };


string address = "http://1111.ip138.com/ic.asp";
string str = GetWebStr(address);


try
{
//提取外網ip數據 [218.104.71.178]
int i1 = str.IndexOf("[") + 1, i2 = str.IndexOf("]");
IP[0] = str.Substring(i1, i2 - i1);


//提取網址說明信息 "來自:安徽省合肥市 聯通"
i1 = i2 + 2; i2 = str.IndexOf("<", i1);
IP[1] = str.Substring(i1, i2 - i1);
}
catch (Exception) { }


return IP;
}


/// <summary>
/// 獲取網址address的返回的文本串數據
/// </summary>
public string GetWebStr(string address)
{
string str = "";
try
{
//從網址中獲取本機ip數據
System.Net.WebClient client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.Default;
str = client.DownloadString(address);
client.Dispose();
}
catch (Exception) { }


return str;
}


/// <summary>
/// 獲取本機的MAC; //在項目-》添加引用....裡面引用System.Management
/// </summary>
public string GetLocalMac()
{
string mac = null;
ManagementObjectSearcher query = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration");
ManagementObjectCollection queryCollection = query.Get();
foreach (ManagementObject mo in queryCollection)
{
if (mo["IPEnabled"].ToString() == "True")
mac = mo["MacAddress"].ToString();
}
return (mac);
}


//只能獲取同網段的遠程主機MAC地址. 因為在標準網路協議下,ARP包是不能跨網段傳輸的,故想通過ARP協議是無法查詢跨網段設備MAC地址的。
[DllImport("Iphlpapi.dll")]
private static extern int SendARP(Int32 dest, Int32 host, ref Int64 mac, ref Int32 length);
[DllImport("Ws2_32.dll")]
private static extern Int32 inet_addr(string ip);
/// <summary>
/// 獲取ip對應的MAC地址
/// </summary>
public string GetMacAddress(string ip)
{
Int32 ldest = inet_addr(ip); //目的ip
Int32 lhost = inet_addr("127.0.0.1"); //本地ip


try
{
Int64 macinfo = new Int64();
Int32 len = 6;
int res = SendARP(ldest, 0, ref macinfo, ref len); //使用系統API介面發送ARP請求,解析ip對應的Mac地址
return Convert.ToString(macinfo, 16);
}
catch (Exception err)
{
Console.WriteLine("Error:{0}", err.Message);
}
return "獲取Mac地址失敗";
}


/// <summary>
/// 獲取主板序列號
/// </summary>
/// <returns></returns>
public string GetBIOSSerialNumber()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_BIOS");
string sBIOSSerialNumber = "";
foreach (ManagementObject mo in searcher.Get())
{
sBIOSSerialNumber = mo["SerialNumber"].ToString().Trim();
}
return sBIOSSerialNumber;
}
catch
{
return "";
}
}


/// <summary>
/// 獲取CPU序列號
/// </summary>
/// <returns></returns>
public string GetCPUSerialNumber()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Processor");
string sCPUSerialNumber = "";
foreach (ManagementObject mo in searcher.Get())
{
sCPUSerialNumber = mo["ProcessorId"].ToString().Trim();
}
return sCPUSerialNumber;
}
catch
{
return "";
}
}
//獲取硬碟序列號
public string GetHardDiskSerialNumber()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
string sHardDiskSerialNumber = "";
foreach (ManagementObject mo in searcher.Get())
{
sHardDiskSerialNumber = mo["SerialNumber"].ToString().Trim();
break;
}
return sHardDiskSerialNumber;
}
catch
{
return "";
}
}


//獲取網卡地址
public string GetNetCardMACAddress()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))");
string NetCardMACAddress = "";
foreach (ManagementObject mo in searcher.Get())
{
NetCardMACAddress = mo["MACAddress"].ToString().Trim();
}
return NetCardMACAddress;
}
catch
{
return "";
}
}

 


/// <summary>
/// 獲得CPU編號
/// </summary>
public string GetCPUID()
{
string cpuid = "";
ManagementClass mc = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuid = mo.Properties["ProcessorId"].Value.ToString();
}
return cpuid;
}


/// <summary>
/// 獲取硬碟序列號
/// </summary>
public string GetDiskSerialNumber()
{
//這種模式在插入一個U盤後可能會有不同的結果,如插入我的手機時
String HDid = "";
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
HDid = (string)mo.Properties["Model"].Value;//SerialNumber
break;//這名話解決有多個物理盤時產生的問題,只取第一個物理硬碟
}
return HDid;


/*ManagementClass mc = new ManagementClass("Win32_PhysicalMedia");
ManagementObjectCollection moc = mc.GetInstances();
string str = "";
foreach (ManagementObject mo in moc)
{
str = mo.Properties["SerialNumber"].Value.ToString();
break;
}
return str;*/
}


/// <summary>
/// 獲取網卡硬體地址
/// </summary>
public string GetMacAddress()
{
string mac = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
mac = mo["MacAddress"].ToString();
break;
}
}
return mac;
}


/// <summary>
/// 獲取IP地址
/// </summary>
public string GetIPAddress()
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if ((bool)mo["IPEnabled"] == true)
{
//st=mo["IpAddress"].ToString();
System.Array ar;
ar = (System.Array)(mo.Properties["IpAddress"].Value);
st = ar.GetValue(0).ToString();
break;
}
}
return st;
}


/// <summary>
/// 操作系統的登錄用戶名
/// </summary>
public string GetUserName()
{
return Environment.UserName;
}

 


/// <summary>
/// 獲取電腦名
/// </summary>
public string GetComputerName()
{
return Environment.MachineName;
}


/// <summary>
/// 操作系統類型
/// </summary>
public string GetSystemType()
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["SystemType"].ToString();
}
return st;
}


/// <summary>
/// 物理記憶體
/// </summary>
public string GetPhysicalMemory()
{
string st = "";
ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
st = mo["TotalPhysicalMemory"].ToString();
}
return st;
}


/// <summary>
/// 顯卡PNPDeviceID
/// </summary>
public string GetVideoPNPID()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_VideoController");
foreach (ManagementObject mo in mos.Get())
{
st = mo["PNPDeviceID"].ToString();
}
return st;
}


/// <summary>
/// 音效卡PNPDeviceID
/// </summary>
public string GetSoundPNPID()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_SoundDevice");
foreach (ManagementObject mo in mos.Get())
{
st = mo["PNPDeviceID"].ToString();
}
return st;
}


/// <summary>
/// CPU版本信息
/// </summary>
public string GetCPUVersion()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_Processor");
foreach (ManagementObject mo in mos.Get())
{
st = mo["Version"].ToString();
}
return st;
}


/// <summary>
/// CPU名稱信息
/// </summary>
public string GetCPUName()
{
string st = "";
ManagementObjectSearcher driveID = new ManagementObjectSearcher("Select * from Win32_Processor");
foreach (ManagementObject mo in driveID.Get())
{
st = mo["Name"].ToString();
}
return st;
}


/// <summary>
/// CPU製造廠商
/// </summary>
public string GetCPUManufacturer()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_Processor");
foreach (ManagementObject mo in mos.Get())
{
st = mo["Manufacturer"].ToString();
}
return st;
}


/// <summary>
/// 主板製造廠商
/// </summary>
public string GetBoardManufacturer()
{
SelectQuery query = new SelectQuery("Select * from Win32_BaseBoard");
ManagementObjectSearcher mos = new ManagementObjectSearcher(query);
ManagementObjectCollection.ManagementObjectEnumerator data = mos.Get().GetEnumerator();
data.MoveNext();
ManagementBaseObject board = data.Current;
return board.GetPropertyValue("Manufacturer").ToString();
}


/// <summary>
/// 主板編號
/// </summary>
public string GetBoardID()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_BaseBoard");
foreach (ManagementObject mo in mos.Get())
{
st = mo["SerialNumber"].ToString();
}
return st;
}


/// <summary>
/// 主板型號
/// </summary>
public string GetBoardType()
{
string st = "";
ManagementObjectSearcher mos = new ManagementObjectSearcher("Select * from Win32_BaseBoard");
foreach (ManagementObject mo in mos.Get())
{
st = mo["Product"].ToString();
}
return st;
}
}
}


/*
* 在很多情況下,你可能都需要得到微機的硬體信息。比如:你想給你的軟體加鎖,不讓別人隨便訪問。


最有效的辦法是獲取CPU的序列號,然後讓你的軟體只能運行在有這樣的CPU序列號的機器上。眾所周知,CPU序列號是唯一的!因此,這樣就可以為你的軟體加鎖了。powered by 25175.net


另外一個需要硬碟信息的例子是:硬碟有幾個分區,每個分區各有多少剩餘空間。當你正在做一個多媒體應用程式的時候,你可能也需要獲得有關音效卡、顯卡的硬體信息。

 

 


本應用程式另一個精彩的應用是:獲取有關係統記憶體的信息,如記憶體地址,記憶體設備等等。


首先,你必須知道這個應用程式的功能是使用System.Management這個類得到的。因此,你需要加上下麵的這句話:


using System.Management;

 


為了獲取硬體信息,你還需要創建一個ManagementObjectSearcher 對象。


ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);


// 硬體
Win32_Processor, // CPU 處理器
Win32_PhysicalMemory, // 物理記憶體條
Win32_Keyboard, // 鍵盤
Win32_PointingDevice, // 點輸入設備,包括滑鼠。
Win32_FloppyDrive, // 軟盤驅動器
Win32_DiskDrive, // 硬碟驅動器
Win32_CDROMDrive, // 光碟驅動器
Win32_BaseBoard, // 主板
Win32_BIOS, // BIOS 晶元
Win32_ParallelPort, // 並口
Win32_SerialPort, // 串口
Win32_SerialPortConfiguration, // 串口配置
Win32_SoundDevice, // 多媒體設置,一般指音效卡。
Win32_SystemSlot, // 主板插槽 (ISA & PCI & AGP)
Win32_USBController, // USB 控制器
Win32_NetworkAdapter, // 網路適配器
Win32_NetworkAdapterConfiguration, // 網路適配器設置
Win32_Printer, // 印表機
Win32_PrinterConfiguration, // 印表機設置
Win32_PrintJob, // 印表機任務
Win32_TCPIPPrinterPort, // 印表機埠
Win32_POTSModem, // MODEM
Win32_POTSModemToSerialPort, // MODEM 埠
Win32_DesktopMonitor, // 顯示器
Win32_DisplayConfiguration, // 顯卡
Win32_DisplayControllerConfiguration, // 顯卡設置
Win32_VideoController, // 顯卡細節。
Win32_VideoSettings, // 顯卡支持的顯示模式。


// 操作系統
Win32_TimeZone, // 時區
Win32_SystemDriver, // 驅動程式
Win32_DiskPartition, // 磁碟分區
Win32_LogicalDisk, // 邏輯磁碟
Win32_LogicalDiskToPartition, // 邏輯磁碟所在分區及始末位置。
Win32_LogicalMemoryConfiguration, // 邏輯記憶體配置
Win32_PageFile, // 系統頁文件信息
Win32_PageFileSetting, // 頁文件設置
Win32_BootConfiguration, // 系統啟動配置
Win32_ComputerSystem, // 電腦信息簡要
Win32_OperatingSystem, // 操作系統信息
Win32_StartupCommand, // 系統自動啟動程式
Win32_Service, // 系統安裝的服務
Win32_Group, // 系統管理組
Win32_GroupUser, // 系統組帳號
Win32_UserAccount, // 用戶帳號
Win32_Process, // 系統進程
Win32_Thread, // 系統線程
Win32_Share, // 共用
Win32_NetworkClient, // 已安裝的網路客戶端
Win32_NetworkProtocol, // 已安裝的網路協議

 

 


上面代碼的Key是一個將被對應正確的數據填入的值。例如,獲取CPU的信息,就需要把Key值設成Win32_Processor。所有Key可能的值,列舉如下:


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_PhysicalMedia
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

 


首先,調用ManagementObjectSearcher實例(在本文中的例子里為searcher )中的Get()方法,該方法將會把返回信息填在這個實例中。然後,你所要做的就是處理這個實例searcher中的數據。


foreach (ManagementObject share in searcher.Get()){// Some Codes ...}


每個ManagementObject的對象中都有一些,我們所需要的數據,當然我們可以接著這麼處理這些數據:


foreach (PropertyData PC in share.Properties){//some codes ...}


本文中代碼的其它部分只是對於ListView控制項的一些操作,很簡單,就不再詳述了!
*/

 

轉自:http://blog.csdn.net/scimence/article/details/44812243


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 說來也奇怪,筆者Dell台式機前幾天系統提示有更新,筆者對系統進行了更新,可昨天開機後,就出現了C0000034正在應用更新操作的情況,且電腦一直沒反應,上網搜了一下帖子,發現複製粘貼的帖子好多,基本都一個模式,又是刪除這文件,又是進入哪個系統,好複雜。這裡筆者說一下親身體驗過且可行的方法。 1.重 ...
  • 小程式: 行家看看年前,公司開發了微信小程式,我負責後端開發,其中遇到一些坑,分享一下小程式語音錄製和播放微信錄音不能計時,需要自己計時錄音文件是微信獨有格式,只能微信本身播放,否則需要工具轉換為Mp3等通用格式才可以錄音播放不能直接用標簽src引入,需要將語音文件下載到本地後才可以正常播放。錄音播... ...
  • # identity資料庫 ## 創建空資料庫 交給ef管理 ### 添加asp.net identity包 ``` Install-Package Microsoft.AspNet.Identity.EntityFramework Install-Package Microsoft.AspNet.... ...
  • 一、StackPanel StackPanel是以堆疊的方式顯示其中的控制項 1、可以使用Orientation屬性更改堆疊的順序分為水平方向(Orientation="Horizontal")和豎直方向(Orientation="Vertical"),以保證要實現的效果。 二、WrapPanel 以 ...
  • Server=(localdb)\\mssqllocaldb; Database=xxxxx; Serve=伺服器名;Database=資料庫名 Server=(localdb)\\mssqllocaldb; AttachDbFilename=xxxx.mdf;Initial Catalog=xxx ...
  • 在認識WPF之前,在windows開發人員都是基於坐標來將控制項放在正確的位置上,控制項的大小也是由軟體人員來指定。這對於軟體人員來說比較無聊痛苦。但是在WPF中這種痛苦且無聊的工作沒有了,這得益於WPF的佈局。 佈局就是將一些控制項在窗體上進行排布。一般來說都是靠坐標來的,WPF也支持這種方法,但是WP ...
  • 微軟的Bing搜索引擎首頁每天都會提供了一些有趣的圖片,下麵使用正則表達式獲取圖片的地址,不管是在手機app還是在網站上都是很好的圖片素材,而且每天更新,非常不錯。 首先訪問微軟的API,該地址返回的是xml文本,獲取xml文本後使用正則表達式匹配url節點中的內容,加上必應主頁鏈接即可獲得圖片的真 ...
  • using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Security.Cryptography; using System.Text; using Syste ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...