Link to home
Start Free TrialLog in
Avatar of Murtuza111000
Murtuza111000

asked on

Machine Identification

Hi experts,

I need to uniquely identify a computer system. I need this for generating a unique value based on the hardware, it could be the network card number or probably the CPU speed.

Literally anything that does not change when the system is formatted. I am currently using ActiveLock but every time you format the system the ActiveLock key changes. I hope that my requirement is clear.

Thankx for any help in advance
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murtuza111000
Murtuza111000

ASKER

That was really very quick TimCottee, I will checkout the link
Went thru the project, but would this work on a system where there is no network card installed.
:ping:
Avatar of Ark
Hi
'For w95/98 via direct memory access.NT/2000 doesn't map
'these addresses into process space, so this code cause GPF.
'See section below how to get these info for NT/2000.

Option Explicit
Private Type BiosData
  Date As Date
  Manufacturer As String
  Version As String
End Type

'Change following declaration to fit your vb version

Private Declare Sub GetMem1 Lib "msvbvm50.dll" (ByVal MemAddress As Long, var As Byte)

Private Function GetBIOSData() As BiosData
 Dim p As Byte, MemAddr As Long, sBios As String
 Dim i As Integer
 sBios = "" 
 MemAddr = &HFE061
 For i = 0 To 25
     Call GetMem1(MemAddr + i, p)
     If p = 0 Then p = 32
     sBios = sBios & Chr$(p)
 Next i
 GetBIOSData.Version = sBios
 MemAddr = &HFFFF5
 sBios = "" 
 For i = 0 To 7
     Call GetMem1(MemAddr + i, p)
     If p = 0 Then p = 32
     sBios = sBios & Chr$(p)
 Next i
 GetBIOSData.Date = CDate(sBios)
 MemAddr = &HFE030
 sBios = "" 
 For i = 0 To 18
     Call GetMem1(MemAddr + i, p)
     If p = 0 Then p = 32
     sBios = sBios & Chr$(p)
 Next i
 GetBIOSData.Manufacturer = sBios
End Function

Private Sub Form_Load()
 Dim bd As BiosData
 bd = GetBIOSData
 Text1 = "BIOS date = " & bd.Date & vbCrLf & "Manufacturer = " & bd.Manufacturer & vbCrLf & "BIOS ver.
= " & bd.Version
End Sub

' For all platforms via registry reading. Can not check on NT, but you can just search your registry using regedit
and change data location in code:

---Bas module code---
Private Const REG_SZ As Long = 1
Private Const REG_DWORD As Long = 4
Private Const HKEY_LOCAL_MACHINE As Long = &H80000002

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal
lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As
Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData
As Long) As Long

Private Function regQuery_A_Key(ByVal hKey As Long, ByVal sRegKeyPath As String, ByVal sRegSubKey As
String) As Variant
 Dim iPos As Integer
 Dim lKeyHandle As Long
 Dim lRet As Long
 Dim lDataType As Long
 Dim lBufferSize As Long
 Dim lBuffer As Long
 Dim sBuffer As String
 Dim arBuffer() As Byte
 lKeyHandle = 0
 lBufferSize = 0
 regQuery_A_Key = "" 
 lRet = RegOpenKey(hKey, sRegKeyPath, lKeyHandle)
 If lKeyHandle = 0 Then GoTo FuncFail
 lRet = RegQueryValueEx(lKeyHandle, sRegSubKey, 0&, lDataType, ByVal 0&, lBufferSize)
 If lKeyHandle = 0 Then GoTo FuncFail
 Select Case lDataType
        Case REG_SZ:       ' String
             sBuffer = Space(lBufferSize)
             lRet = RegQueryValueEx(lKeyHandle, sRegSubKey, 0&, 0&, ByVal sBuffer, lBufferSize)
             If lRet = ERROR_SUCCESS Then
                iPos = InStr(1, sBuffer, Chr(0))
                If iPos > 0 Then
                    regQuery_A_Key = Left(sBuffer, iPos - 1)
                Else
                    regQuery_A_Key = sBuffer
                End If
             End If
        Case REG_DWORD:
             lRet = RegQueryValueEx(lKeyHandle, sRegSubKey, 0&, lDataType, lBuffer, 4&)            
                           ' 4& = 4-byte word (long integer)
             If lRet = ERROR_SUCCESS Then
                regQuery_A_Key = lBuffer
             End If
        Case Else:
 End Select
FuncFail:
lRet = RegCloseKey(lKeyHandle)
End Function

Public Function GetBiosVer() As String
  GetBiosVer = regQuery_A_Key(HKEY_LOCAL_MACHINE, "Enum\Root\*PNP0C01\0000", "BiosVersion")
End Function

Public Function GetBiosDate() As String
  GetBiosDate = regQuery_A_Key(HKEY_LOCAL_MACHINE, "Enum\Root\*PNP0C01\0000", "BiosDate")
End Function

Public Function GetBiosMfr() As String
GetBiosMfr = regQuery_A_Key(HKEY_LOCAL_MACHINE, "Enum\Root\*PNP0C01\0000", "BiosName")
End Function

'--- Form code---
' Add one command button at form
Private Sub Command1_Click()
Me.Print "BiosDate = "; GetBiosDate
Me.Print "BiosVersion = "; GetBiosVer
Me.Print "BiosName = "; GetBiosMfr
End Sub

Cheers
Ark,

Thank you for this peice of code,I checked it on a Win98 system and it runs fine, but the alternate method on a WinNT4.0 and Windows2000 does not seen to work. There is no registry key PNP0C01\0000 on any of the winnt systems

I find HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\Root\*PNP0C01\PnPBIOS_8 key on a WinNT2000 system but again this no values like "BiosDate",BiosName" and "BiosVersion"

And again even if I do locate these entries in the registry, they are editable values by the user, now that is a different question how many users may actually play around these values, and also that system might be refreshing the values at boot.

TimCottee's solution might work only on systems that have a network card. something similar that might work on systems without network card would be perfect.
Correction:

TimCottee's solution might work only on systems that have a network card. something similar that might
work on systems without network card would be perfect.

TimCottee's solution does not work on systems that do not have a network card.
Thank you Ark for the suggestion, but as I mentioned that this approach has its pitfall, although TimCottee's partially answers my question but that is something what I am looking for.

I think I will settle for TimCottee's suggestion.

Thank you for the help.
Do let me know If my question can be fully answered

Thanks