C Hwang C Hwang - 1 month ago 6
C# Question

How to make C# executable file PC Specific

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

Answer

You can easily verify the computer name using:

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

Environment.MachineName