I know that a question has already been asked about generating a unique ID for a machine but my question is slightly different.
I want to know whether there are any other methods (API calls?) to get hardware information and NOT use WMI. I understand from MSDN that WMI is introduced in Win2000 so it doesnt seem to be available in Win98. I have an application that has to run even on Win98 (I know it sucks but what can you do?) and still get hold of hardware information.
I've done this several times for licensing projects. For the hard drive serial number use:
private static extern long GetVolumeInformation(string PathName, StringBuilder VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32 VolumeSerialNumber, ref UInt32 MaximumComponentLength, ref UInt32 FileSystemFlags, StringBuilder FileSystemNameBuffer, UInt32 FileSystemNameSize);
Use the VolumeSerialNumber
that is returned by the function.
Also, you may have thought about using the Windows Product ID (Located at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
). Be careful, a large number of Windows XP users have pirated copies and share the same product keys.
You can combine different hardware information in order to create a unique key.
For example, CPU ID, MAC address etc etc. You retrieve them, combine them, encrypt them and you have a unique representation of the hardware setup of this machine.
Try googling about the subject: how to read hardware information.
From what I can see there is a very useful post in CodeProject: How To Get Hardware Information (CPU ID, MainBoard Info, Hard Disk Serial, System Information , ...).
Look through the WinAPI's kernel32 and user32 library. It has all sorts of goodies like EnumDisplayDevices
, GetLogicalDrives
, GlobalMemoryStatus
, GetVolumeInformation
, etc, etc. I Like to use PInvoke to browse the API since it gives me the C# wrapper code - but MSDN will have it all as well in the Windows SDK.
@novatrust's answer regarding the hard drive serial is a good one - but can be combined with more. I've provided the GetVolumeInformation
API link to pinvoke above, but a simple Google should work as well.