Obtain the hardware information of the machine (cpu id serial number, motherboard information, hard disk serial number, and system information:
41 keywords: hardware CPU motherboard hard drive font: [large, medium, small]
In many cases, you may need to obtain the hardware information of the microcomputer. For example, you want to lock your software and prevent others from accessing it at will.
The most effective way is to get the serial number of the CPU, and then let your software run on a machine with such a serial number. As we all know, the CPU serial number is unique! Therefore, you can lock your software.
Another example that requires hard disk information is: the hard disk has several partitions, and each partition has its own space. When you are creating a multimedia application, you may also need to obtain hardware information about the sound card and video card.
Another wonderful application of this application is to obtain information about the system memory, such as the memory address and memory device.
Code usage
First, you must know that the function of this application is obtained by using the system. management class. Therefore, you need to add the following sentence:
using System.Management;
To obtain hardware information, you also need to create a managementobjectsearcher object.
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);
The key of the code above is a value that will be filled in with the correct data. For example, to obtain CPU information, you need to set the key value to win32_processor. The possible values of all keys are listed as follows:
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_classiccomclassset.pdf
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_shorttopmonitor
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_logical1_access
Win32_logicalshareauditing
Win32_logicalpolicsecuritysetting
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_aspnet1_v114322
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
First, call the get () method in the managementobjectsearcher instance (in this example, It is searcher). This method will fill in the returned information in this instance. Then, all you need to do is to process the data in the searcher instance.
foreach (ManagementObject share in searcher.Get())
{
// Some Codes ...
}
Each managementobject object contains some data that we need. Of course, we can process the data as follows:
foreach (PropertyData PC in share.Properties)
{
//some codes ...
}
The other part of the code in this article is just some operations on the listview control, which is very simple and will not be detailed again!