我使用 C# 编写了一个程序,并使用高级安装程序制作了 exe 文件,它运行良好,但我想让这个 exe 文件在一台计算机上运行,因为有些客户 拿走 exe 并将这个 exe 给另一个,我想 privint 并保护我的作品
最佳答案
在您想要 .exe 的机器上运行下面的代码。要处理的文件(它将为您提供这台机器的 MAC 地址)。 2.将这个MAC地址添加到下面的代码中 3.将下面的代码添加到您的C#代码中,以确保它只在具有正确MAC地址(唯一)的机器上运行
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;
}
}
}
关于c# - 如何让exe文件只在一台电脑上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914378/