CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    May 2003
    Location
    Australia
    Posts
    155

    retrieving a unique ID for your system. code included.

    Hi all,

    Have seen numerous posts on this forum about how to obtain some kind of unique ID to identify a particular computer so developers can better protect their software with serial numbers etc.

    Well, I have put together some code that might help people achieve this in some way.

    I have come up with 5 functions (all written exclusively in VB), that can retrieve a unique value for a given system:

    - GetBIOSSerial() ' serial number from BIOS on motherboard
    - GetMACAddress() ' serial number from first ethernet card
    - GetHardDriveSerial(IDE_NUMBER) ' Hard Drive serial number
    - GetVolumeSerial(Drive) ' Formatted partition serial number
    - GetProductID() ' Windows product ID

    Unfortunately tho (there is always a downside) only 2 of these functions are guarunteed to return a value on all versions of Windows (GetVolumeSerial, and GetProductID).

    GetBIOSSerial() may work depending on the BIOS, or it may just be it doesnt work on Win98 or earlier (I have only been able to test this on 3 machines so far, 2 Win98 machines which fail, and a Win2K machine which works). If anyone can further add to this, that would be great.

    GetMACAddress() retrieves the MAC Address of an ethernet adapter which is guaranteed to be globally unique, however, in Win95 and WinNT, the card appears to need to be connected to the network. In Win2K and WinXP, the ethernet card must be enabled but doesnt have to be connected. Also, ID's may still be returned for Virtual Networks, and I dont know if these can be guaranteed to be globally unique or only on the current network. If anyone can further add to this, please do

    GetHardDriveSerial(IDE_NUMBER) returns the serial number for the physical hard drive connected to one of your 4 IDE channels (ie, PRIMARY_MASTER, PRIMARY_SLAVE, SECONDARY_MASTER, SECONDARY_SLAVE). This is not the same as the volume serial number which is assigned when formatting a partition on your hard drive. Again, I have only been able to test this on 3 machines, and it has worked on 2 of them, a Win98 machine, and a Win2K machine).

    GetVolumeSerial(Drive) returns the above mentioned serial number assigned to a partition when you format it. This function appears to work on all OS's, but will be changed if you reformat your hard drive. If no Drive is specified, it checks the partition the system is installed on.

    GetProductID() returns the Windows Product ID. Granted, GetProductID may not be globally unique, but can be a useful ID to use if you want to combine some of these functions together. I am not sure if this value is the same for all computers who have had Windows installed from the same CD or not (perhaps someone can clarify this). Also, this value is stored in the registry, and might be easily modified (does Windows allow it to be modified, and does it cause problems in Windows if it is changed? Perhaps someone can clarify this too).

    There are still a few questions to answer, which is why I have posted it up here on this forum. I have attached the code for people to test on different systems. It would be good to have a more definite idea on which OS's the different functions will work on, and how reliable they are.

    Please feel free to suggest changes if there are bugs, or if you know of other values or IDs that can be added to this code base, or if there are more reliable ways to retrieve the values in these functions for different OS's.

    It should also be noted, that when using the code, it would probably be safer to include it in your own project rather than as a separate DLL, unless you compress it and add a CRC32 checker to it. But even then, the best of the best can still work their way around it. But we should at least make them work for it

    Cheers everyone, hope to hear peoples input on these functions.

    Tinbum747.
    Attached Files Attached Files
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

  2. #2
    Hi,
    I just tested your code and i must say i have been looking for somthing like this for a little while..

    I loaded it and it ran just fine.. here is the out put if you wanted some sort of feedback on it..:

    Windows Product ID = [55277-OEM-001190#-#####]
    BIOS Serial Number = [4573N21]
    MAC Address = [05345000]
    System Volume Serial Number = [1409368185]
    Primary Master HDD Serial Number = [WD-WMAATA688138
    Beta Testers Needed. Free Access www.drussellsoft.com to sign-up

  3. #3
    Join Date
    May 2003
    Location
    Australia
    Posts
    155
    No problem drsoft,

    I know the frustration

    Do you mind letting me know what OS you are using and how old/new your machine is?

    Just wanting to find out if any of the functions have limitations on certain versions of Windows.

    Has anyone else tested this code with success or failure??

    I currently only have access to a limited number of machines and OS's, so cant do a very thorough testing of these functions, so if others would be able to test on their mahines, that would be great.

    Cheers.
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

  4. #4
    Hi there,
    I have a Dell 2350 2.0 Ghz 1 gig ram Win XP Pro

    There is one problem i did find, With the speed of my system, it took about 30 secs to get data..

    D.
    Beta Testers Needed. Free Access www.drussellsoft.com to sign-up

  5. #5
    Ok, here is another test.. I just bought the dell, but i do have a Pentium 3 800 with 256 ram and windows 2000.

    I compiled the project on my dell and transfered the EXE to my other system. The load took almost a minute, no errors
    Beta Testers Needed. Free Access www.drussellsoft.com to sign-up

  6. #6
    Join Date
    May 2003
    Location
    Australia
    Posts
    155
    Hi again,

    Thanks for testing for me drsoft.

    re: speed issue ...

    Are you running the app from floppy disk or from hard drive?

    Dont know how closely you have looked at the code, but the GetHardDriveSerial() function actually extracts the SmartVSD.vdx driver it uses from a resource file and saves it to the same folder the app is running from each time the function is called. My sample app calls it for each IDE channels (thus performing the extraction 4 times).

    No, this is not optimized code , I really only put it together for testing purposes, with the idea that if the SmartVSD driver is not present on the system, it will look for it in the same path the app is run from.

    You can modify this code if you wanted to distribute the driver as a separate file or if you knew it would be present on the users system.

    See if that speeds it up for you

    Cheers
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

  7. #7

    Question

    Hi,
    Here is your code for Get VolumeSerial:

    "System Volume Serial Number = [" & oUniqueIDs.GetVolumeSerial() & "]" & vbCrLf

    My output is:
    Primary Master HDD Serial Number = [WD-WMAATA688138

    Notice that the "]" is not there? I don't know if this could cause the load?? My CPU goes to 100% when i run and i have tried to debug but i got nothing...

    What do you think?
    Beta Testers Needed. Free Access www.drussellsoft.com to sign-up

  8. #8
    Join Date
    Jun 2001
    Posts
    23
    I am using NT and your code looks working fine.

    this will be helpful.

    thanks

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Win2kProfessional - fine

    few seconds, and info seems fine (but is it possible Bios serial is 0?)

    '----------------------------------------------------------------------
    Windows Product ID = [51873-270-#######-#####]
    BIOS Serial Number = [00000000]
    MAC Address = [0A0CCCA79B2]
    System Volume Serial Number = [1895596035]
    Primary Master HDD Serial Number = [11XCXK]
    '----------------------------------------------------------------------
    My machine is a Laptop Compass,
    255 mb of ram
    p4 - 1Gh
    with win2k professional, servicepack 3


    ps:
    drsoft, which is your volume label? it might contain some chars that is better to replace
    ie:
    "System Volume Serial Number = [" & replace(oUniqueIDs.GetVolumeSerial(),chr(0),"") & "]" & vbCrLf
    Last edited by Cimperiali; June 26th, 2003 at 08:25 AM.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  10. #10
    Join Date
    Jan 2002
    Location
    Quebec/Canada
    Posts
    124
    Worked fine on my computer, p4 1500 (1.x secs to run) and I got it all except BIOS Serial number (win98 here)

    One thing, it seems to get my PPP Mac address, instead of my ethernet adaptor. I think the chances are you get more unique # with the network adaptor then with the PPP one. Just my 2¢

    Nice work, I may use it sometime if you don't mind

    Heulsay

  11. #11
    Hi,
    Yes, i have it now.. The program ran less than 3 secs.. The problem was my system.. I had a few other things running that sared the same resources... (I.E. Norton) It seems they use the Vol. # and the MAC Address.. Don't know why???


    But I unloaded Norton and it ran just fine... Can i Use it?

    DrussellSoft.com
    Beta Testers Needed. Free Access www.drussellsoft.com to sign-up

  12. #12
    Join Date
    May 2003
    Location
    Australia
    Posts
    155
    Hi again,

    Thanks all for testing.

    Cimperiali: Never seen a BIOS serial number of 0 before - I am starting to suspect that Win95/98/ME doesnt support the BIOS serial retrieval, and returns an empty string. Since you are using Win2K, it sounds like the routine to retrieve the BIOS serial worked, but maybe your BIOS doesnt support it.

    Heulsay: There are different methods for retrieving a MAC address, depending on what network protocols are installed, etc. I actually use 2 different methods (depending on the version of Windows). Both should be protocol independant, but only finds the MAC address of the first ethernet adapter returned, so if you have multiple ethernet adapters (including virtual adapters, like AOL adapters etc.), then a virtual adapter might be the first adapter returned, thus returning a PPP MAC address rather than the physical ethernet adapter MAC address. Am sure there is probably a way to check if a virtual adapter or not - I didnt look

    All are welcome to use this code in your own projects.

    As I have mentioned previously, the HDD serial number routine is not very well optimised, so you might like to make some changes to it.

    To add further protection to your applications, I would recommend using some kind of packing utility with a CRC checksum to guard against your app being changed (easily). If people are going to hack your code, we should at least make them earn it

    Cheers everyone.
    Tinbum747
    Zen-Programming:

    If a compiler beeps in the IDE forest, and nobody hears it, was there really a bug?

  13. #13
    Join Date
    Apr 2005
    Location
    Colombo, Sri Lanka
    Posts
    27

    Re: retrieving a unique ID for your system. code included.

    checked on a Win2000 pro. P4 1.8GHz 512MB
    works fine, 2 secs. but no BIOs SN

    Windows Product ID = [51###-0##-5182###-09###]
    BIOS Serial Number = []
    MAC Address = [08A141D98C]
    System Volume Serial Number = [1281114780]

    thanks a lot Tinbum747
    Primary Master HDD Serial Number = [3KC24KPH]

  14. #14
    Join Date
    Jun 2005
    Posts
    60

    Re: retrieving a unique ID for your system. code included.

    tested it at work on a P4 3.2G, 1024 MB, WinXP pro sp2.

    Windows Product ID = [#####-OEM-#######-#####]
    BIOS Serial Number = [To Be Filled By O.E.M.]
    MAC Address = [0112FDDA21A]
    System Volume Serial Number = [1108655217]
    Primary Master HDD Serial Number = [WD-WCAM93640416]

    strange BIOS SN !!!



    and on a slow and old celereon 600, 64 MB, Win2000 pro.

    no bios serial number
    no Primary Master HDD SN

    Windows Product ID = [#####-OEM-#######-#####]
    BIOS Serial Number = []
    MAC Address = [0021FF8899]
    System Volume Serial Number = [-599317886]

    is it normal that the System Volume SN is negative ?
    Last edited by sergelac; June 29th, 2005 at 06:05 AM.

  15. #15
    Join Date
    Feb 2005
    Posts
    25

    Re: retrieving a unique ID for your system. code included.

    this is the out put of my system
    /////////////////////////////////////
    Windows Product ID = [51876-007-3339415-05946]
    BIOS Serial Number = []
    MAC Address = [011112D71C7]
    System Volume Serial Number = [-1405280034]

    //////////////////////////////////////////

    win2000 server version 5.0 servicepack 4
    hardware x86 family

Page 1 of 2 12 LastLast

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