-
May 22nd, 2001, 04:24 AM
#1
How to get some computer dependent information?
Hi,
I want to get some computer dependent information within my program that will be absolutely different in every computer. I've thought that getting the serial number of the motherboard or the hard disk will do but I don't know if there is a better way for doing this within the WIN32 API. Is there?
Thanks.
-
May 22nd, 2001, 04:39 AM
#2
Re: How to get some computer dependent information?
So, you want to get some sort of a "computer id" ?
- the motherboard doesn't have a readable serial number (at least some don't)
- some CPUs have an ID, but not all (and it may be disabled)
- hard drives do not have readable serial numbers
So, you can do it like this : generate a random number (at least 64 or 128 bits to be secure) and write it somewhere in the registry. When you want your machine id, just re-read this value (or generate a new one if it's not present)
It looks like this :
read registry value
if read ok
return value
else
generate new value
write value in registry
return value
-
May 22nd, 2001, 04:51 AM
#3
Re: How to get some computer dependent information?
That's a very good idea.
Thanks.
-
May 22nd, 2001, 04:53 AM
#4
Re: How to get some computer dependent information?
Use UuidCreate() to create a 16 byte string guranteed to be unique from one pc to the next providing they each have a network card. Write this value to the registry - and when you want the computers id, read the value back ...
[snippet from MSDN]
[/b]
UuidCreate
The UuidCreate function creates a new UUID.
[/b]
#include <rpc.h>
RPC_STATUS RPC_ENTRY UuidCreate(
UUID * Uuid
);
Parameters
Uuid
Returns a pointer to the created UUID.
Return Values
Value Meaning
RPC_S_OK Success
RPC_S_UUID_LOCAL_ONLY The UUID is guaranteed to be unique to this machine only.
RPC_S_UUID_NO_ADDRESS Cannot get Ethernet or token-ring hardware address for this computer
Remarks
In Windows NT, versions 4.0 and later, Windows 95, DCOM release, and Windows 98, UuidCreate returns RPC_S_UUID_LOCAL_ONLY when the originating machine does not have an ethernet/token ring (IEEE 802.x) address. In this case, the generated UUID is a valid identifier, and is guaranteed to be unique among all UUIDs generated on the machine. However, the possibility exists that another machine without an ethernet/token ring address generated the identical UUID. Therefore you should never use this UUID to identify an object that is not strictly local to your machine. Machines with ethernet/token ring addresses generate UUIDs that are guaranteed to be globally unique.
Jase
<no witty trailer supplied>
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
-
May 22nd, 2001, 05:10 AM
#5
Re: How to get some computer dependent information?
-
May 22nd, 2001, 06:10 AM
#6
Re: How to get some computer dependent information?
There's another solution, you can get the serial number of a volume (C:, D:, ...). Take a look to the function GetVolumeInformation.
The ID is unique to the computer and changes only when the hard drive is formatted. This is better than getting a random number or a GUID, cause these will change if you need to generate a new ID (for example, your application is removed and installed again).
Hope it helps,
David
-
May 22nd, 2001, 06:31 AM
#7
Re: How to get some computer dependent information?
Hi,
You said that the serial number of the hard drive changes with format. Do you know if that new serial number is random? or if you can change this after formating?
Thanks.
-
May 22nd, 2001, 06:41 AM
#8
Re: How to get some computer dependent information?
Hmmmm...
GUID is a better solution if you are planning to run your application across a network. If you are running across a network then a GUID is guaranteed unique on every pc, and if you have to regenerate a GUID, then that is no problem as the new number is still going to be unique. But with the disk volume serial number, it is not guaranteed unique. Any other pc on the network may have the same serial.
If you are running your application on a single pc environment, then both methods are equally as good.
Jase
<no witty trailer supplied>
Jase
www.slideshowdesktop.com
View your images and photos on your desktop with ease using SlideShow Desktop, the desktop wallpaper manager for Microsoft Windows....
-
May 22nd, 2001, 06:55 AM
#9
Re: How to get some computer dependent information?
Hi,
Do you know if the serial number given by format is random? and if you can change the serial number after formating?
Thanks.
-
May 22nd, 2001, 07:00 AM
#10
Re: How to get some computer dependent information?
The serial number is random and it can not be changed after formatting the hard drive.
This is a good choice if you are generating a serial number for an application based in a computer, because it changes only with a format, but it's true that is not guaranteed to be unique in a network. If you need to be absoluty sure that there are no 2 pcs with the same ID, use the GUID, but remember that once you remove the registry entry (when you uninstall the application) the ID will be different next time in the same computer.
-
May 22nd, 2001, 07:04 AM
#11
Re: How to get some computer dependent information?
Thanks,
I think I'll use a combination of those two solutions.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|