Click here to Skip to main content
5,788,961 members and growing! (20,304 online)
Email Password   helpLost your password?
Languages » C# » Samples     Intermediate

Generating a unique computer/user ID using C#

By Gratemyl

How to generate a unique computer/user ID, using C#, which can be used for user tracking, software licensing, etc.
C#, Windows, .NET, Visual Studio, Dev

Posted: 11 Apr 2006
Updated: 11 Apr 2006
Views: 36,257
Bookmarked: 15 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
23 votes for this Article.
Popularity: 1.40 Rating: 1.03 out of 5
22 votes, 95.7%
1
0 votes, 0.0%
2
1 vote, 4.3%
3
0 votes, 0.0%
4
0 votes, 0.0%
5

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



Location: Netherlands Netherlands

Other popular C# articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 17 of 17 (Total in Forum: 17) (Refresh)FirstPrevNext
AnswerMotherBoard Serial NumbermemberMad Philosopher5:56 26 Jun '08  
GeneralRe: MotherBoard Serial NumbermvpJohn Simmons / outlaw programmer2:32 17 Jul '08  
GeneralNot really uniquememberRay Cassick17:24 11 Apr '06  
GeneralRe: Not really uniquememberFabrice Vergnenegre22:53 11 Apr '06  
GeneralRe: Not really uniquememberGratemyl3:08 12 Apr '06  
GeneralRe: Not really uniquememberFabrice Vergnenegre10:55 12 Apr '06  
GeneralRe: Not really uniquememberGratemyl13:29 12 Apr '06  
GeneralRe: Not really uniquememberBorv12:00 19 Oct '06  
GeneralRe: Not really uniquememberOneSoftware19:51 14 Apr '07  
GeneralRe: Not really uniquememberOneSoftware20:49 23 Apr '07  
GeneralRe: Not really uniquememberIbrahim Dwaikat4:57 8 Oct '08  
GeneralRe: Not really uniquememberGratemyl3:07 12 Apr '06  
GeneralRe: Not really uniquememberGratemyl3:09 12 Apr '06  
AnswerRe: Not really uniquememberhk112:46 23 Aug '07  
GeneralRe: Not really uniquemvpJohn Simmons / outlaw programmer2:34 17 Jul '08  
GeneralRemovable DrivesmemberFelipe Amorim10:44 11 Apr '06  
GeneralRe: Removable DrivesmemberGratemyl11:14 11 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 11 Apr 2006
Editor: Smitha Vijayan
Copyright 2006 by Gratemyl
Everything else Copyright © CodeProject, 1999-2009
Web10 | Advertise on the Code Project