-3

I am making a normal c# program and want it to be un-sharable. The way I want to approach this, is I have heard of code that could target and find the name of the user's pc. I have the name of my friend's PC, and want to have only work when he runs it.

The people I distribute it will inevitably try to copy and share it for another price, but I want to make a specific program for them every time that specifies only my buyer's desktop user name.

After some research I have been linked to here: https://msdn.microsoft.com/en-us/library/aa394554(v=vs.85).aspx

But I can't really make sense of it. Is there any function/line of code that straight gets the name of the user's pc and checks if it matches the pc I sold to? Thanks <3

Edit: When I am referring to the username, I am talking about the "Computer Name" under This PC > properties

C Hwang
  • 1
  • 2
  • What you really want is some type of software key to limit the use of your application because another user can easily change the name of their computer. Check out this [question](http://stackoverflow.com/questions/599837/how-to-generate-and-validate-a-software-license-key) – juharr Nov 01 '16 at 15:05
  • 2
    This is an awful idea. What if the person decides to rename their computer? – rory.ap Nov 01 '16 at 15:05
  • you also can filter it on macaddress – Timon Post Nov 01 '16 at 15:06
  • @DaPosto -- what if they buy a new NIC? – rory.ap Nov 01 '16 at 15:07
  • think about some authorization server or something like that, otherwise support will be a nightmare - I mean for each user use hardcoded sting into the source ... - bad idea in a firstplace – Vladimir Nov 01 '16 at 15:07
  • Yes, or use licence keys for specific users and authorization. And based on that you could verify a user and his rights. – Timon Post Nov 01 '16 at 15:11
  • Thanks for the suggestions, but I can assure you none of my customers in my school will understand even the concept of a computer name, nor that it would even be relevant. – C Hwang Nov 01 '16 at 15:12

2 Answers2

0

You can easily verify the computer name using:

if(Environment.MachineName != "ComputerName")
{
    Environment.Exit(-1);
}

Environment.MachineName

Chrille
  • 1,435
  • 12
  • 26
0

You can use the computer name with Environment.MachineName. The problem with that is that anyone with the same computer name will be able to run the program. One way used to uniquely identify machines is getting the network card MAC address:

var macAddr = 
    NetworkInterface.GetAllNetworkInterfaces()
    .Where(nic => nic.OperationalStatus == OperationalStatus.Up)
    .Select(nic => nic.GetPhysicalAddress().ToString())
    .FirstOrDefault();

You should also fail-safe to the possibility of not having a NIC.

Yeray Cabello
  • 411
  • 3
  • 12