Click here to Skip to main content
Licence 
First Posted 11 Apr 2006
Views 86,603
Bookmarked 29 times

Generating a unique computer/user ID using C#

By | 11 Apr 2006 | Article
How to generate a unique computer/user ID, using C#, which can be used for user tracking, software licensing, etc.

Demo project screen-shot

Introduction and Background

I recently had to create an application with a registration system which would be used by many users at the same time, each of them purchasing their own license.

The idea was the following: the user purchases a license key, which he/she then enters into the application (which could be downloaded freely). The application would contact a central server, which would return an activation request serial number. This would then be sent to the license reseller, who would generate an activation key, which would in turn be entered into the application by the user.

I needed some way of uniquely identifying each computer with ease, to ensure that no two users could use the same license key, yet each user could establish several connections to the server.

In this article, I will show you how I accomplished this task.

The actual code

I solved the problem by making use of the computer name, username, and user domain, the number of processors, and the number of logical drives which are installed on the computer. This way, even a multi-user system would require each user to register their own copy of the application, but no user could use the same license on more than one computer.

First, create a new Windows application, and add a button plus textbox to your form.

In the button1_click routine, add the following code:

textBox1.Text =  // Set the contents of textBox1 to:
    Environment.ProcessorCount + "/" +       //
    // {number of processors}/{machine name}/
    Environment.MachineName + "/" + 
    // {user domain}\{username}/
    Environment.UserDomainName + "\\" +
    // {number of logical drives}
    Environment.UserName + "/" + 
    Environment.GetLogicalDrives().Length;   //

The code should be fairly easy to understand.

Points of Interest

The disadvantage to this method is that the same conditions can be simulated, but with some difficulties. This method should not be used where expensive software is licensed - I used this for cheap licensing of small software.

This method still needs some enhancements to be ready for big software.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Gratemyl



Netherlands Netherlands

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralUnique Id for my System PinmemberMamuly19:10 25 Jul '10  
GeneralSerial number is only suppose to be unique Pinmembermichaelnoam5:10 16 Jun '10  
GeneralMy vote of 1 Pinmemberknowge0:53 19 May '10  
AnswerMachineGUID PinmemberKurtz NatureBoy3:05 29 Apr '10  
GeneralAnother Simple and Reliable Alternative PinmemberWeifen Luo14:26 1 Mar '10  
GeneralUnique Machine ID PinmemberAnindya Chatterjee4:09 3 Mar '09  
AnswerMotherBoard Serial Number PinmemberMad Philosopher4:56 26 Jun '08  
GeneralRe: MotherBoard Serial Number PinmvpJohn Simmons / outlaw programmer1:32 17 Jul '08  
Reliably identifying a given system is fraught with danger.
 
MAC addresses are unreliable for system ID. Even if the system contains one or more NICs, if ALL of the NICs are disabled, you won't be able to retrieve any MAC address. Besides that, they can be changed by the user.
 
The Win32_BaseBoard class contains the serial number of the board, but if the BIOS gets updated by the user, the chances are very good that the serial number property will be empty or null (the same goes for the Win32_BIOS class).
 
You also can't use Win32_ComputerSystemProduct class, because machines not built by a retail system builder (like Dell, Acer, Toshiba, HP, etc) will have a UUID of FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF.
 
I'm still looking for a reliable and repeatable way to identify a system.
 

"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

GeneralRe: MotherBoard Serial Number PinmemberChizI12:31 4 Nov '09  
GeneralNot really unique PinmemberRay Cassick16:24 11 Apr '06  
GeneralRe: Not really unique PinmemberFabrice Vergnenegre21:53 11 Apr '06  
GeneralRe: Not really unique PinmemberGratemyl2:08 12 Apr '06  
GeneralRe: Not really unique PinmemberFabrice Vergnenegre9:55 12 Apr '06  
GeneralRe: Not really unique PinmemberGratemyl12:29 12 Apr '06  
GeneralRe: Not really unique PinmemberBorv11:00 19 Oct '06  
GeneralRe: Not really unique PinmemberOneSoftware18:51 14 Apr '07  
GeneralRe: Not really unique PinmemberOneSoftware19:49 23 Apr '07  
GeneralRe: Not really unique PinmemberIbrahim Dwaikat3:57 8 Oct '08  
GeneralRe: Not really unique PinmemberGratemyl2:07 12 Apr '06  
GeneralRe: Not really unique PinmemberGratemyl2:09 12 Apr '06  
AnswerRe: Not really unique Pinmemberhk111:46 23 Aug '07  
GeneralRe: Not really unique PinmvpJohn Simmons / outlaw programmer1:34 17 Jul '08  
GeneralRemovable Drives PinmemberFelipe Amorim9:44 11 Apr '06  
GeneralRe: Removable Drives PinmemberGratemyl10:14 11 Apr '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 11 Apr 2006
Article Copyright 2006 by Gratemyl
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid