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

Posted on 2006-04-15
Last Modified: 2012-06-27
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
Question by:mlcktmguy
    1 Comment
    LVL 29

    Accepted Solution

    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
        Set obsrv = Nothing
        Set obItm = Nothing
    End Function

    Private Sub Command1_Click()
    MsgBox BIOSSerial
    End Sub

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now