CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Jan 2001
    Posts
    39

    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.



  2. #2
    Join Date
    Apr 2000
    Location
    Lyon / France
    Posts
    352

    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




  3. #3
    Join Date
    Jan 2001
    Posts
    39

    Re: How to get some computer dependent information?

    That's a very good idea.
    Thanks.



  4. #4
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    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.
    ...

  5. #5
    Join Date
    Jan 2001
    Posts
    39

    Re: How to get some computer dependent information?

    Thanks.


  6. #6
    Join Date
    May 2001
    Posts
    22

    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


  7. #7
    Join Date
    Jan 2001
    Posts
    39

    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.


  8. #8
    Join Date
    Mar 2000
    Location
    Birmingham, England
    Posts
    2,520

    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.
    ...

  9. #9
    Join Date
    Jan 2001
    Posts
    39

    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.



  10. #10
    Join Date
    May 2001
    Posts
    22

    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.




  11. #11
    Join Date
    Jan 2001
    Posts
    39

    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
  •  





Click Here to Expand Forum to Full Width

Featured