Imports System
Imports System.Management
Public Class Form1
Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, ByVal lpVolumeSerialNumber As Long, ByVal lpMaximumComponentLength As Long, ByVal lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Dim reg As Object, Pid As Object, GUID As Object
Dim LENGUID As Long, LENPID As Long, TempS As String
Dim x As Long, SPID As String, SGUID As String, HWID As String
Const regPID = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionProductId"
Const regGUID = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftCryptographyMachineGuid"
Public Function CreateID() As String
On Error Resume Next
reg = CreateObject("wscript.shell")
Pid = Replace(reg.regread(regPID), "-", "")
GUID = Replace(reg.regread(regGUID), "-", "")
LENPID = Len(Pid)
LENGUID = Len(GUID)
For x = 1 To LENPID
TempS = Hex((Asc(Mid$(Pid, x, 1)) Xor 23) Xor 14)
SPID = SPID & TempS
Next x
SPID = StrReverse(SPID)
For x = 1 To LENGUID
TempS = Hex((Asc(Mid$(GUID, x, 1)) Xor 23) Xor 14)
SGUID = SGUID & TempS
Next x
SGUID = StrReverse(SGUID)
HWID = StrReverse(SGUID & SPID)
CreateID = HWID
End Function
Friend Function GetProcessorId() As String
Dim strProcessorId As String = String.Empty
Dim query As New SelectQuery("Win32_processor")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strProcessorId = info("processorId").ToString()
Next
Return strProcessorId
End Function
Friend Function GetMACAddress() As String
Dim mc As ManagementClass = New ManagementClass("Win32_NetworkAdapterConfiguration")
Dim moc As ManagementObjectCollection = mc.GetInstances()
Dim MACAddress As String = String.Empty
For Each mo As ManagementObject In moc
If (MACAddress.Equals(String.Empty)) Then
If CBool(mo("IPEnabled")) Then MACAddress = mo("MacAddress").ToString()
mo.Dispose()
End If
MACAddress = MACAddress.Replace(":", String.Empty)
Next
Return MACAddress
End Function
Friend Function GetVolumeSerial(Optional ByVal strDriveLetter As String = "C") As String
Dim disk As ManagementObject = New ManagementObject(String.Format("win32_logicaldisk.deviceid=""{0}:""", strDriveLetter))
disk.Get()
Return disk("VolumeSerialNumber").ToString()
End Function
Friend Function GetMotherBoardID() As String
Dim strMotherBoardID As String = String.Empty
Dim query As New SelectQuery("Win32_BaseBoard")
Dim search As New ManagementObjectSearcher(query)
Dim info As ManagementObject
For Each info In search.Get()
strMotherBoardID = info("SerialNumber").ToString()
Next
Return strMotherBoardID
End Function
End Class