Click here to Skip to main content
13,249,174 members (34,086 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 11 Apr 2006

Generating a unique computer/user ID using C#

, 11 Apr 2006
Rate this:
Please Sign up or sign in to vote.
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.


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

Netherlands Netherlands
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
majidsharifi31-Mar-14 2:07
membermajidsharifi31-Mar-14 2:07 
GeneralUnique Id for my System Pin
Mamuly25-Jul-10 20:10
memberMamuly25-Jul-10 20:10 
GeneralSerial number is only suppose to be unique Pin
michaelnoam16-Jun-10 6:10
membermichaelnoam16-Jun-10 6:10 
GeneralMy vote of 1 Pin
knowge19-May-10 1:53
memberknowge19-May-10 1:53 
AnswerMachineGUID Pin
Kurtz NatureBoy29-Apr-10 4:05
memberKurtz NatureBoy29-Apr-10 4:05 
GeneralAnother Simple and Reliable Alternative Pin
Weifen Luo1-Mar-10 15:26
memberWeifen Luo1-Mar-10 15:26 
GeneralUnique Machine ID Pin
Anindya Chatterjee3-Mar-09 5:09
memberAnindya Chatterjee3-Mar-09 5:09 
AnswerMotherBoard Serial Number Pin
Mad Philosopher26-Jun-08 5:56
memberMad Philosopher26-Jun-08 5:56 
GeneralRe: MotherBoard Serial Number Pin
John Simmons / outlaw programmer17-Jul-08 2:32
mvpJohn Simmons / outlaw programmer17-Jul-08 2:32 
GeneralRe: MotherBoard Serial Number Pin
ChizI4-Nov-09 13:31
memberChizI4-Nov-09 13:31 
GeneralNot really unique Pin
Ray Cassick11-Apr-06 17:24
memberRay Cassick11-Apr-06 17:24 
GeneralRe: Not really unique Pin
Fabrice Vergnenegre11-Apr-06 22:53
memberFabrice Vergnenegre11-Apr-06 22:53 
GeneralRe: Not really unique Pin
Gratemyl12-Apr-06 3:08
memberGratemyl12-Apr-06 3:08 
GeneralRe: Not really unique Pin
Fabrice Vergnenegre12-Apr-06 10:55
memberFabrice Vergnenegre12-Apr-06 10:55 
GeneralRe: Not really unique Pin
Gratemyl12-Apr-06 13:29
memberGratemyl12-Apr-06 13:29 
GeneralRe: Not really unique Pin
Borv19-Oct-06 12:00
memberBorv19-Oct-06 12:00 
GeneralRe: Not really unique Pin
OneSoftware14-Apr-07 19:51
memberOneSoftware14-Apr-07 19:51 
GeneralRe: Not really unique Pin
OneSoftware23-Apr-07 20:49
memberOneSoftware23-Apr-07 20:49 
GeneralRe: Not really unique Pin
Ibrahim Dwaikat8-Oct-08 4:57
memberIbrahim Dwaikat8-Oct-08 4:57 
GeneralRe: Not really unique Pin
Gratemyl12-Apr-06 3:07
memberGratemyl12-Apr-06 3:07 
GeneralRe: Not really unique Pin
Gratemyl12-Apr-06 3:09
memberGratemyl12-Apr-06 3:09 
AnswerRe: Not really unique Pin
hk1123-Aug-07 2:46
memberhk1123-Aug-07 2:46 
GeneralRe: Not really unique Pin
John Simmons / outlaw programmer17-Jul-08 2:34
mvpJohn Simmons / outlaw programmer17-Jul-08 2:34 
GeneralRemovable Drives Pin
Felipe Amorim11-Apr-06 10:44
memberFelipe Amorim11-Apr-06 10:44 
GeneralRe: Removable Drives Pin
Gratemyl11-Apr-06 11:14
memberGratemyl11-Apr-06 11:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 11 Apr 2006
Article Copyright 2006 by Gratemyl
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid