1

I am writing a basic licensing class for our program. I would like to tie this license to the server so they cannot move the license and expect it to work.

The program is run locally on each workstation from a shared drive on the server. Majority of our customers run on a peer 2 peer network since they are smaller companies and only have a few computers.

I'd like to get a unique identifier for the server so when the workstation starts the application, it will verify the license is running against the correct server.

I have almost completed the class except I cannot figure out how to get a consistent unique identifier for the server.

Also, I am writing this in C#.net.

Any suggestions?

Thanks!

ErocM
  • 4,505
  • 24
  • 94
  • 161
  • C# can be easily decompiled and modified, it will be really easy to make it work anywhere no matter how unique your identifier will be – Daniel May 06 '11 at 13:27

2 Answers2

2

Sounds like you want the computer's Security Identifier (SID).

string fqdn = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()).HostName;

int firstDot = fqdn.IndexOf('.');
string host = fqdn.Substring(0, firstDot);
string domain = fqdn.Substring(firstDot + 1);

NTAccount account = new NTAccount(domain, host + "$");
SecurityIdentifier sid =
    (SecurityIdentifier)account.Translate(typeof(SecurityIdentifier));

// we're done, show the results:
Console.WriteLine(account.Value);
Console.WriteLine(sid.Value);

(Code to get identifier copied from here. Tested, though. It works.)

In reference to the discussion below, the way that would be most "gentle" to your users is to license by host name. This is the way dotNetCharting does it (or did it a few years ago when I bought their software). Basing on hardware or the computer's SID is prone to change and necessitates relicensing/activation when the hardware changes or the OS is re-installed. The first line in the code above returns the fully qualified domain, which you could use for this purpose.

Tim Coker
  • 6,484
  • 2
  • 31
  • 62
  • Thats one way yes, but would be "reset" with each OS install. – EKS May 06 '11 at 13:26
  • Yup. But if you change hardware, your licensing is gone, too. Not an clean answer, other than tying to host name, maybe. But that would be relatively easy to game. – Tim Coker May 06 '11 at 13:29
  • True, and you can do like microsoft and support X changes. But if you changed mothboard and CPU its a new machine in my book – EKS May 06 '11 at 13:32
  • I keep getting "Some or all identity references could not be translated." I've tried all of the domains and computers on our network. Any suggestions? – ErocM May 06 '11 at 13:44
  • How would I get information, motherboard and cpu, like that remotely on a p2p network? – ErocM May 06 '11 at 13:46
  • Write out what you're getting for the domain and computer name? I don't have a pc available that's not part of a domain to test on at the moment, unfortunately. – Tim Coker May 06 '11 at 13:49
  • This is a great start. I have most of what I want. I just need to grab a few more items. Thanks for a push in the right direction. – ErocM May 08 '11 at 02:36
0

Get the serial number of the CPU and system harddrive and mainboard then hash it. You can off course mix up what hardware serials/models information you take.

Article on codeproject that explains how to get the information: http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

EKS
  • 5,543
  • 6
  • 44
  • 60