views:

598

answers:

5

I'm new to vc++ language so I want to get system unique id using vc++ language. so please can anybody help me in coding how to get system unique id?

+4  A: 

You want to look at CoCreateGuid (http://msdn.microsoft.com/en-us/library/ms688568(VS.85).aspx).

Blindy
How does that identify the system?
anon
It doesn't, it's just an (almost) system unique identifier.
Blindy
There is no function that could generate same id later. So this function doesn't identify system in any way.
Kirill V. Lyadvinsky
To answer the 3 comments above, you generate then store the GUID and use it to identify your machine on a wider system like a network or whatever the context is. No different to getting the MAC address from a network card only this doesn't require your system has a network card. +1 for being less constrained than using a MAC address.
Rich
+1  A: 

Why not use the MAC address from the network card. This should be unique but will change if your change the network card.

See the api GetAdaptersInfo. reference http://msdn.microsoft.com/en-us/library/aa365917(VS.85).aspx

Rich
At least three reasons - it may not have a network card, it may have more than one network card, the network card(s) may be changed.
anon
What about systems that have no network card?
MadKeithV
If more than one network card, choose the first. If network card changes , have a re-registration process. If no network card, give the machine to a museum and buy a new one. ;.)I agree MAC address isn't a 100% solution, but it should cater for the vast majority of situations.
Rich
In retrospect generating a GUID rather than using MAC address is probably better. You then don't need a network card to be installed. Having said that , what system would need a unique identifier unless it was networked in the first place? .. hmmmmm....we definitely need more context from the question.
Rich
A: 

IF you're looking to create a unique ID based on a specific machine, one of the ways I can think of is using good old boost.

For instance, you can look up one of the boost candidate libraries called UUID (GUID generation) and you could look up boost::filesystem. Using the filesystem you could get creation dates on some of the system files, and use those strings to generate a GUID.

Just a thought, hope it helps

  • you can find the UUID library here

    • you can find the Filesystem library documentation here
Maciek
That identifies the date of the Windows installation. If I have to reinstall, or touch the files somehow, I get a new id.
anon
A: 

One value that I've seen used is the hard disk volume ID of the C-drive. It will change when you swap the drive though.

MadKeithV
A: 

As I think the answers so far and the responses to them indicate, the real answer is not to write code that requires a unique system ID. This is very easy to do, in fact (as there is no such ID) it is the only sensible way to write applications. Anything that depends on drive serial number, MAC addresses etc. will inevitably break when the system is changed or upgraded.

anon