1 public static string GetMacAddress()
2 {
3 ManagementClass class2 = new ManagementClass("Win32_NetworkAdapterConfiguration");
4 foreach (ManagementObject obj2 in class2.GetInstances())
5 {
6 if (obj2["IPEnabled"].ToString() == "True")
7 {
8 return obj2["MacAddress"].ToString();
9 }
10 }
11 return null;
12 }
13
14 /// <summary>
15 /// 取CPU ID
16 /// </summary>
17 /// <returns></returns>
18 public static string GetCpuId()
19 {
20 return GetHardwareInfo(HardwareEnum.Win32_Processor, "ProcessorId");
21 }
22
23 /// <summary>
24 /// 取硬盘SN
25 /// </summary>
26 /// <returns></returns>
27 public static string GetHardDiskSN()
28 {
29 return GetHardwareInfo(HardwareEnum.Win32_PhysicalMedia, "SerialNumber");
30 }
31
32 /// <summary>
33 /// 取硬件信息
34 /// </summary>
35 /// <param name="hardType"></param>
36 /// <param name="propKey"></param>
37 /// <returns></returns>
38 public static string GetHardwareInfo(HardwareEnum hardType , string propKey)
39 {
40 ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + hardType);
41 var hardInfos= searcher.Get();
42 foreach (var hardInfo in hardInfos)
43 {
44 if (hardInfo.Properties[propKey] != null)
45 {
46 return hardInfo.Properties[propKey].Value.ToString();
47 }
48 }
49 return "";
50 }
51
52 public enum HardwareEnum
53 {
54 Win32_1394Controller
55 ,Win32_1394ControllerDevice
56 ,Win32_Account
57 ,Win32_AccountSID
58 ,Win32_ACE
59 ,Win32_ActionCheck
60 ,Win32_AllocatedResource
61 ,Win32_ApplicationCommandLine
62 ,Win32_ApplicationService
63 ,Win32_AssociatedBattery
64 ,Win32_AssociatedProcessorMemory
65 ,Win32_BaseBoard
66 ,Win32_BaseService
67 ,Win32_Battery
68 ,Win32_Binary
69 ,Win32_BindImageAction
70 ,Win32_BIOS
71 ,Win32_BootConfiguration
72 ,Win32_Bus
73 ,Win32_CacheMemory
74 ,Win32_CDROMDrive
75 ,Win32_CheckCheck
76 ,Win32_CIMLogicalDeviceCIMDataFile
77 ,Win32_ClassicCOMApplicationClasses
78 ,Win32_ClassicCOMClass
79 ,Win32_ClassicCOMClassSetting
80 ,Win32_ClassicCOMClassSettings
81 ,Win32_ClassInfoAction
82 ,Win32_ClientApplicationSetting
83 ,Win32_CodecFile
84 ,Win32_COMApplication
85 ,Win32_COMApplicationClasses
86 ,Win32_COMApplicationSettings
87 ,Win32_COMClass
88 ,Win32_ComClassAutoEmulator
89 ,Win32_ComClassEmulator
90 ,Win32_CommandLineAccess
91 ,Win32_ComponentCategory
92 ,Win32_ComputerSystem
93 ,Win32_ComputerSystemProcessor
94 ,Win32_ComputerSystemProduct
95 ,Win32_COMSetting
96 ,Win32_Condition
97 ,Win32_CreateFolderAction
98 ,Win32_CurrentProbe
99 ,Win32_DCOMApplication
100 ,Win32_DCOMApplicationAccessAllowedSetting
101 ,Win32_DCOMApplicationLaunchAllowedSetting
102 ,Win32_DCOMApplicationSetting
103 ,Win32_DependentService
104 ,Win32_Desktop
105 ,Win32_DesktopMonitor
106 ,Win32_DeviceBus
107 ,Win32_DeviceMemoryAddress
108 ,Win32_DeviceSettings
109 ,Win32_Directory
110 ,Win32_DirectorySpecification
111 ,Win32_DiskDrive
112 ,Win32_DiskDriveToDiskPartition
113 ,Win32_DiskPartition
114 ,Win32_DisplayConfiguration
115 ,Win32_DisplayControllerConfiguration
116 ,Win32_DMAChannel
117 ,Win32_DriverVXD
118 ,Win32_DuplicateFileAction
119 ,Win32_Environment
120 ,Win32_EnvironmentSpecification
121 ,Win32_ExtensionInfoAction
122 ,Win32_Fan
123 ,Win32_FileSpecification
124 ,Win32_FloppyController
125 ,Win32_FloppyDrive
126 ,Win32_FontInfoAction
127 ,Win32_Group
128 ,Win32_GroupUser
129 ,Win32_HeatPipe
130 ,Win32_IDEController
131 ,Win32_IDEControllerDevice
132 ,Win32_ImplementedCategory
133 ,Win32_InfraredDevice
134 ,Win32_IniFileSpecification
135 ,Win32_InstalledSoftwareElement
136 ,Win32_IRQResource
137 ,Win32_Keyboard
138 ,Win32_LaunchCondition
139 ,Win32_LoadOrderGroup
140 ,Win32_LoadOrderGroupServiceDependencies
141 ,Win32_LoadOrderGroupServiceMembers
142 ,Win32_LogicalDisk
143 ,Win32_LogicalDiskRootDirectory
144 ,Win32_LogicalDiskToPartition
145 ,Win32_LogicalFileAccess
146 ,Win32_LogicalFileAuditing
147 ,Win32_LogicalFileGroup
148 ,Win32_LogicalFileOwner
149 ,Win32_LogicalFileSecuritySetting
150 ,Win32_LogicalMemoryConfiguration
151 ,Win32_LogicalProgramGroup
152 ,Win32_LogicalProgramGroupDirectory
153 ,Win32_LogicalProgramGroupItem
154 ,Win32_LogicalProgramGroupItemDataFile
155 ,Win32_LogicalShareAccess
156 ,Win32_LogicalShareAuditing
157 ,Win32_LogicalShareSecuritySetting
158 ,Win32_ManagedSystemElementResource
159 ,Win32_MemoryArray
160 ,Win32_MemoryArrayLocation
161 ,Win32_MemoryDevice
162 ,Win32_MemoryDeviceArray
163 ,Win32_MemoryDeviceLocation
164 ,Win32_MethodParameterClass
165 ,Win32_MIMEInfoAction
166 ,Win32_MotherboardDevice
167 ,Win32_MoveFileAction
168 ,Win32_MSIResource
169 ,Win32_NetworkAdapter
170 ,Win32_NetworkAdapterConfiguration
171 ,Win32_NetworkAdapterSetting
172 ,Win32_NetworkClient
173 ,Win32_NetworkConnection
174 ,Win32_NetworkLoginProfile
175 ,Win32_NetworkProtocol
176 ,Win32_NTEventlogFile
177 ,Win32_NTLogEvent
178 ,Win32_NTLogEventComputer
179 ,Win32_NTLogEventLog
180 ,Win32_NTLogEventUser
181 ,Win32_ODBCAttribute
182 ,Win32_ODBCDataSourceAttribute
183 ,Win32_ODBCDataSourceSpecification
184 ,Win32_ODBCDriverAttribute
185 ,Win32_ODBCDriverSoftwareElement
186 ,Win32_ODBCDriverSpecification
187 ,Win32_ODBCSourceAttribute
188 ,Win32_ODBCTranslatorSpecification
189 ,Win32_OnBoardDevice
190 ,Win32_OperatingSystem
191 ,Win32_OperatingSystemQFE
192 ,Win32_OSRecoveryConfiguration
193 ,Win32_PageFile
194 ,Win32_PageFileElementSetting
195 ,Win32_PageFileSetting
196 ,Win32_PageFileUsage
197 ,Win32_ParallelPort
198 ,Win32_Patch
199 ,Win32_PatchFile
200 ,Win32_PatchPackage
201 ,Win32_PCMCIAController
202 ,Win32_Perf
203 ,Win32_PerfRawData
204 ,Win32_PerfRawData_ASP_ActiveServerPages
205 ,Win32_PerfRawData_ASPNET_114322_ASPNETAppsv114322
206 ,Win32_PerfRawData_ASPNET_114322_ASPNETv114322
207 ,Win32_PerfRawData_ASPNET_ASPNET
208 ,Win32_PerfRawData_ASPNET_ASPNETApplications
209 ,Win32_PerfRawData_IAS_IASAccountingClients
210 ,Win32_PerfRawData_IAS_IASAccountingServer
211 ,Win32_PerfRawData_IAS_IASAuthenticationClients
212 ,Win32_PerfRawData_IAS_IASAuthenticationServer
213 ,Win32_PerfRawData_InetInfo_InternetInformationServicesGlobal
214 ,Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator
215 ,Win32_PerfRawData_MSFTPSVC_FTPService
216 ,Win32_PerfRawData_MSSQLSERVER_SQLServerAccessMethods
217 ,Win32_PerfRawData_MSSQLSERVER_SQLServerBackupDevice
218 ,Win32_PerfRawData_MSSQLSERVER_SQLServerBufferManager
219 ,Win32_PerfRawData_MSSQLSERVER_SQLServerBufferPartition
220 ,Win32_PerfRawData_MSSQLSERVER_SQLServerCacheManager
221 ,Win32_PerfRawData_MSSQLSERVER_SQLServerDatabases
222 ,Win32_PerfRawData_MSSQLSERVER_SQLServerGeneralStatistics
223 ,Win32_PerfRawData_MSSQLSERVER_SQLServerLatches
224 ,Win32_PerfRawData_MSSQLSERVER_SQLServerLocks
225 ,Win32_PerfRawData_MSSQLSERVER_SQLServerMemoryManager
226 ,Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationAgents
227 ,Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationDist
228 ,Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationLogreader
229 ,Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationMerge
230 ,Win32_PerfRawData_MSSQLSERVER_SQLServerReplicationSnapshot
231 ,Win32_PerfRawData_MSSQLSERVER_SQLServerSQLStatistics
232 ,Win32_PerfRawData_MSSQLSERVER_SQLServerUserSettable
233 ,Win32_PerfRawData_NETFramework_NETCLRExceptions
234 ,Win32_PerfRawData_NETFramework_NETCLRInterop
235 ,Win32_PerfRawData_NETFramework_NETCLRJit
236 ,Win32_PerfRawData_NETFramework_NETCLRLoading
237 ,Win32_PerfRawData_NETFramework_NETCLRLocksAndThreads
238 ,Win32_PerfRawData_NETFramework_NETCLRMemory
239 ,Win32_PerfRawData_NETFramework_NETCLRRemoting
240 ,Win32_PerfRawData_NETFramework_NETCLRSecurity
241 ,Win32_PerfRawData_Outlook_Outlook
242 ,Win32_PerfRawData_PerfDisk_PhysicalDisk
243 ,Win32_PerfRawData_PerfNet_Browser
244 ,Win32_PerfRawData_PerfNet_Redirector
245 ,Win32_PerfRawData_PerfNet_Server
246 ,Win32_PerfRawData_PerfNet_ServerWorkQueues
247 ,Win32_PerfRawData_PerfOS_Cache
248 ,Win32_PerfRawData_PerfOS_Memory
249 ,Win32_PerfRawData_PerfOS_Objects
250 ,Win32_PerfRawData_PerfOS_PagingFile
251 ,Win32_PerfRawData_PerfOS_Processor
252 ,Win32_PerfRawData_PerfOS_System
253 ,Win32_PerfRawData_PerfProc_FullImage_Costly
254 ,Win32_PerfRawData_PerfProc_Image_Costly
255 ,Win32_PerfRawData_PerfProc_JobObject
256 ,Win32_PerfRawData_PerfProc_JobObjectDetails
257 ,Win32_PerfRawData_PerfProc_Process
258 ,Win32_PerfRawData_PerfProc_ProcessAddressSpace_Costly
259 ,Win32_PerfRawData_PerfProc_Thread
260 ,Win32_PerfRawData_PerfProc_ThreadDetails_Costly
261 ,Win32_PerfRawData_RemoteAccess_RASPort
262 ,Win32_PerfRawData_RemoteAccess_RASTotal
263 ,Win32_PerfRawData_RSVP_ACSPerRSVPService
264 ,Win32_PerfRawData_Spooler_PrintQueue
265 ,Win32_PerfRawData_TapiSrv_Telephony
266 ,Win32_PerfRawData_Tcpip_ICMP
267 ,Win32_PerfRawData_Tcpip_IP
268 ,Win32_PerfRawData_Tcpip_NBTConnection
269 ,Win32_PerfRawData_Tcpip_NetworkInterface
270 ,Win32_PerfRawData_Tcpip_TCP
271 ,Win32_PerfRawData_Tcpip_UDP
272 ,Win32_PerfRawData_W3SVC_WebService
273 ,Win32_PhysicalMedia
274 ,Win32_PhysicalMemory
275 ,Win32_PhysicalMemoryArray
276 ,Win32_PhysicalMemoryLocation
277 ,Win32_PNPAllocatedResource
278 ,Win32_PnPDevice
279 ,Win32_PnPEntity
280 ,Win32_PointingDevice
281 ,Win32_PortableBattery
282 ,Win32_PortConnector
283 ,Win32_PortResource
284 ,Win32_POTSModem
285 ,Win32_POTSModemToSerialPort
286 ,Win32_PowerManagementEvent
287 ,Win32_Printer
288 ,Win32_PrinterConfiguration
289 ,Win32_PrinterController
290 ,Win32_PrinterDriverDll
291 ,Win32_PrinterSetting
292 ,Win32_PrinterShare
293 ,Win32_PrintJob
294 ,Win32_PrivilegesStatus
295 ,Win32_Process
296 ,
297 /// <summary>
298 /// CPU信息
299 /// </summary>
300 Win32_Processor
301 ,Win32_ProcessStartup
302 ,Win32_Product
303 ,Win32_ProductCheck
304 ,Win32_ProductResource
305 ,Win32_ProductSoftwareFeatures
306 ,Win32_ProgIDSpecification
307 ,Win32_ProgramGroup
308 ,Win32_ProgramGroupContents
309 ,Win32_ProgramGroupOrItem
310 ,Win32_Property
311 ,Win32_ProtocolBinding
312 ,Win32_PublishComponentAction
313 ,Win32_QuickFixEngineering
314 ,Win32_Refrigeration
315 ,Win32_Registry
316 ,Win32_RegistryAction
317 ,Win32_RemoveFileAction
318 ,Win32_RemoveIniAction
319 ,Win32_ReserveCost
320 ,Win32_ScheduledJob
321 ,Win32_SCSIController
322 ,Win32_SCSIControllerDevice
323 ,Win32_SecurityDescriptor
324 ,Win32_SecuritySetting
325 ,Win32_SecuritySettingAccess
326 ,Win32_SecuritySettingAuditing
327 ,Win32_SecuritySettingGroup
328 ,Win32_SecuritySettingOfLogicalFile
329 ,Win32_SecuritySettingOfLogicalShare
330 ,Win32_SecuritySettingOfObject
331 ,Win32_SecuritySettingOwner
332 ,Win32_SelfRegModuleAction
333 ,Win32_SerialPort
334 ,Win32_SerialPortConfiguration
335 ,Win32_SerialPortSetting
336 ,Win32_Service
337 ,Win32_ServiceControl
338 ,Win32_ServiceSpecification
339 ,Win32_ServiceSpecificationService
340 ,Win32_SettingCheck
341 ,Win32_Share
342 ,Win32_ShareToDirectory
343 ,Win32_ShortcutAction
344 ,Win32_ShortcutFile
345 ,Win32_ShortcutSAP
346 ,Win32_SID
347 ,Win32_SMBIOSMemory
348 ,Win32_SoftwareElement
349 ,Win32_SoftwareElementAction
350 ,Win32_SoftwareElementCheck
351 ,Win32_SoftwareElementCondition
352 ,Win32_SoftwareElementResource
353 ,Win32_SoftwareFeature
354 ,Win32_SoftwareFeatureAction
355 ,Win32_SoftwareFeatureCheck
356 ,Win32_SoftwareFeatureParent
357 ,Win32_SoftwareFeatureSoftwareElements
358 ,Win32_SoundDevice
359 ,Win32_StartupCommand
360 ,Win32_SubDirectory
361 ,Win32_SystemAccount
362 ,Win32_SystemBIOS
363 ,Win32_SystemBootConfiguration
364 ,Win32_SystemDesktop
365 ,Win32_SystemDevices
366 ,Win32_SystemDriver
367 ,Win32_SystemDriverPNPEntity
368 ,Win32_SystemEnclosure
369 ,Win32_SystemLoadOrderGroups
370 ,Win32_SystemLogicalMemoryConfiguration
371 ,Win32_SystemMemoryResource
372 ,Win32_SystemNetworkConnections
373 ,Win32_SystemOperatingSystem
374 ,Win32_SystemPartitions
375 ,Win32_SystemProcesses
376 ,Win32_SystemProgramGroups
377 ,Win32_SystemResources
378 ,Win32_SystemServices
379 ,Win32_SystemSetting
380 ,Win32_SystemSlot
381 ,Win32_SystemSystemDriver
382 ,Win32_SystemTimeZone
383 ,Win32_SystemUsers
384 ,Win32_TapeDrive
385 ,Win32_TemperatureProbe
386 ,Win32_Thread
387 ,Win32_TimeZone
388 ,Win32_Trustee
389 ,Win32_TypeLibraryAction
390 ,Win32_UninterruptiblePowerSupply
391 ,Win32_USBController
392 ,Win32_USBControllerDevice
393 ,Win32_UserAccount
394 ,Win32_UserDesktop
395 ,Win32_VideoConfiguration
396 ,Win32_VideoController
397 ,Win32_VideoSettings
398 , Win32_VoltageProbe
399 ,Win32_WMIElementSetting
400 ,Win32_WMISetting
401 }
转载于:https://www.cnblogs.com/davidyang78/archive/2011/09/21/2183148.html