问题
I wrote a program using C# and make exe file using advanced installer and it work good but i want to make this exe file work in one computer, because some clints take exe and give this exe to another and i want to privint that and protect my works
回答1:
run the code below on the machine that you want your .exe. file to work on (it will give you this machines MAC address). 2. Add this MAC address to the code below 3. Add the code below to your C# code to ensure that it only runs on the machine with the correct MAC address (unique)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
namespace OneMachine
{
class Program
{
static void Main(string[] args)
{
string clientMAC = "XX-XX-XX-XX-XX-XX"; // put the correct value here when you know it
string thisComputerMAC = GetMACAddress2();
Console.WriteLine("MAC:" + thisComputerMAC); // remove this when necessary
if (clientMAC == thisComputerMAC)
{
Console.WriteLine("this is the right computer");
} else
{
Console.WriteLine("PROGRAM WONT RUN ON THIS COMPUTER");
}
}
public static string GetMACAddress2()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
String sMacAddress = string.Empty;
foreach (NetworkInterface adapter in nics)
{
if (sMacAddress == String.Empty)// only return MAC Address from first card
{
//IPInterfaceProperties properties = adapter.GetIPProperties(); Line is not required
sMacAddress = adapter.GetPhysicalAddress().ToString();
}
} return sMacAddress;
}
}
}
reference: C# Get Computer's MAC address "OFFLINE"
回答2:
I think what you want would be some sort of licence key and an authorization method.
A quick google turned up this article which you may find useful.
http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer
回答3:
u can create the security constrain for exe like
- by Giving unique password
- By Entering the serial Key i.e. Licence Key which will know to u only or create random serial key generator based on the system.
回答4:
- get the MAC address of the computer that you want the .exe file to work on (in windows type: C:\getmac (see:https://helpdesk.latech.edu/index.php?option=com_content&task=view&id=207&Itemid=67 ).
- add the following c# code to your application ..... this code finds the computers MAC address each time it runs : C# Get Computer's MAC address "OFFLINE"
- in your c# code, check to see if the computers MAC address matches the 'allowed' MAC address.
回答5:
You can allow only one user run your program by using a hardware ID to identify the user using the application or you can use a licensing system.
来源:https://stackoverflow.com/questions/35914378/how-to-make-exe-file-work-on-one-computer-only