Unique machine ID

How can I get an ID that is the same for one machine across reboots, but it is different for each machine?

It must exist on both Windows 9x and NT/2000.
Who is Participating?
arcusdConnect With a Mentor Commented:
you can try using the volume id of the hard disk..if u want to use
u can try this code

'drive info
Public Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Public Const GETDI_SERIAL = 1
Public Const GETDI_LABEL = 2
Public Const GETDI_TYPE = 3

Function GetDriveInfo(strDrive As String, iType As Integer)
   Dim SerialNum As Long
   Dim strLabel As String
   Dim strType As String
   Dim lRetVal As Long
   strLabel = Space(256)
   strType = Space(256)
   lRetVal = GetVolumeInformation(strDrive, strLabel, Len(strLabel), SerialNum, 0, 0, strType, Len(strType))
   Select Case iType
      Case Is = 1
         GetDriveInfo = CStr(SerialNum)
      Case Is = 2
         GetDriveInfo = strLabel
      Case Is = 3
         GetDriveInfo = strType
   End Select

End Function

so to get the volumeID of the hd

volid = getDriveInf("c",1)

"The code shows you User ID, Hostname, IP adress, and Port number of the local machine."
luisrAuthor Commented:
Sometimes the computer will not have access to the internet or even a network adapter installed. I don't think the IP address would do it.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

The hostname is a character string, easily obtained by Ruchi's suggested method (or several others).  But users can change the CPU name.
A couple of years ago, Intel got in very hot Public Relations waters for wanting to put serial numbers in the CPUs for this very purpose.  The privacy implications are unacceptable to most people, so the computer hardware is (mostly) anonymous and what you're asking for doesn't exist.  The Internet industry has somewhat gotten around this by the use of cookies.  Cookies, in essence, are unique files that you would store on each machine, and you would put unique data in the file, or in the filename, so you could retrieve it later.  Within a corporate setting, this is probably just as acceptable as uniquely ID'ing the hardware.
luisrAuthor Commented:
It does not have a hardware ID... some kind of data that is generated at Windows setup and will remain the same after each boot. The idea is for a program to know it is being run on the machine on which it was installed, and not copied to another one.
luisrAuthor Commented:
Oops... In my previous comment "It does not have a hardware ID" should have been "It does not have to be a hardware ID"
Take the value of the Timer method and save it in the registry
luisrAuthor Commented:
arcusd, I guess that should work, I'll give it a try.
luisrAuthor Commented:
I think that will work... but does it work for UNC paths? how?
Information about UNC paths:
I think this is what you are looking for.

Convert from a file path to a UNC path.

luisrAuthor Commented:
My question is if arcusd's routine will work for UNC paths?? If I run my program through the network, how do I know it is valid if I compare the stored volume ID to that of the machine it is running on?
luisrAuthor Commented:
Thanks for the tip, you got me on the right track. I still had to modify it a little bit to work for my situation.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.