Original: C#/vb.net get computer properties (hard drive ID, hard disk capacity, CPU serial number, MAC address, System type)
In the development process, it is often necessary to obtain some properties of the computer, such as obtaining the hard disk ID/CPU serial number/mac address as to encrypt the string.
1. HDD
When I look at some documents on the Internet, I find that many people are very vague about the hard drive serial number.
What is a hard drive serial number? Refers to the identity as a hard drive, but sometimes it is found that the computer hard drive serial number of the colleague is duplicated. So the hard drive identification we can try to test the ID, this how to get the following explanation.
We can run DOS commands, or view the registry to see the serial number of the hard disk. As shown in: All are HGST hts725050a7e630.
In most cases, you can get the following:
Dim as RegistryKey = registry.localmachine Dim subkey = key. OpenSubKey ("hardware\devicemap\scsi\scsi Port 0\scsi Bus 0\target ID 0\logical Unit ID 0" ) Dim bbb = Subkey.getvalue ("Identifier")
It can also be obtained by WMI:
DimCmicwmi as NewSystem.Management.ManagementObjectSearcher ("SELECT * from Win32_DiskDrive") DimDiskId as String 'Numeric ID DimDiskserialnumber as String 'we'll call it serial numbers for the moment. DimDiskmodel as String 'Serial Number for eachCmicwmiobj asManagementObjectinchCmicwmi.get diskId= Cmicwmiobj ("Signature") Diskserialnumber= Cmicwmiobj ("serialnumber") Diskmodel= Cmicwmiobj ("Model") Next
The personal suggestion uses the signature in the Wmiy as the ID, after all is the number, and does not duplicate.
PS: By the way, the capacity of a hard disk, through the property size can get a single hard disk, add up is the total capacity of the computer.
2. CPU Serial Number
Dim as New System.Management.ManagementObjectSearcher ("select * from Win32_Processor") DimasString for each as in Wmi.get = Wmiobj ("processorid") Next
3. MAC address and IP address
DimNetID as String="" DimIp as String DimSearcher as NewManagementObjectSearcher ("SELECT * FROM Win32_NetworkAdapterConfiguration") DimMoc2 asManagementobjectcollection =Searcher. Get () for eachMo asManagementObjectinchmoc2IfMo"ipenabled") ThenNetID= Mo ("MACAddress") IP= Mo ("IpAddress")(0) Exit for End If Next
IPAddress gets an array of two elements, the first of which is the actual IP.
4. Computer system type and physical memory
DimPctype as String DimPcmemory as String DimMos as NewManagementObjectSearcher ("SELECT * from Win32_ComputerSystem") for eachMo as Object inchmos. Get () Pctype= Mo ("SystemType") Pcmemory= Mo ("TotalPhysicalMemory") Next
The system type, the operating system of the computer, or the physical memory, which means running memory.
For example, my current computer configuration is "x64-based PC", "8272879616" -8g
5. Other
Dim UserName = environment.username--Gets the user name Eg:admin
Dim machinename = environment.machinename--Get the computer name Eg:ibm777-pb4dvty
C#/vb.net Get computer properties (hard drive ID, hard disk capacity, CPU serial number, MAC address, System type)