• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3789
  • Last Modified:

How to get CPU Serial No. or other unique machine ID's

I want to 'brand' the data created in my VB6.0 app so that I can recognize data that has been created on another machine.  I am crrently using

Public Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

to get the username and using that to 'brand' the data.  This is working but it is possible that two machines or users coudl return the same value.

Is it possible from within VB6.0 to retrieve the CPU serial number or some other value that would be unique to a machine?  It owuld have ot be some value that would be on one and only one machine.  I could use this for my branding
0
mlcktmguy
Asked:
mlcktmguy
1 Solution
 
nffvrxqgrcfqvvcCommented:
Maybe BIOS serial number... Otherwise I would shoot for computers GUID


Option Explicit

Private Declare Function GetComputerNameW Lib "kernel32" ( _
    ByVal buf As Long, _
    nSize As Long) As Long

Public Function BIOSSerial() As String
 
    Dim B(255)       As Byte
    Dim PC           As String
    Dim obsrv        As Object
    Dim obItm        As Object
    Dim varItm       As Variant

    GetComputerNameW ByVal VarPtr(B(0)), 255
    PC = Left$(B, InStr(B, Chr(0)) - 1)
   
    Set obsrv = GetObject("winmgmts:\\" & PC)
    Set obItm = obsrv.ExecQuery("Select * from Win32_BIOS", , 48)
    For Each varItm In obItm
        BIOSSerial = varItm.SerialNumber
    Next
   
    Set obsrv = Nothing
    Set obItm = Nothing
   
End Function


Private Sub Command1_Click()
MsgBox BIOSSerial
End Sub
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now