如何使exe文件仅在一台计算机上运行

3

我用C#写了一个程序,并使用高级安装程序制作了exe文件,它运行良好。但是我希望这个exe文件只在一台电脑上运行,因为有些客户会将该exe文件转发给其他人,我希望防止这种情况并保护我的作品。


4
我想这就是许可证被发明的原因。 - andreasnico
1
这个问题有太多可能的答案,无法使用。可以让他们输入密码,检查某个硬件的MAC地址,使用某种第三方许可证系统等等。 - Equalsk
4个回答

3

在您想要 .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#离线获取计算机的MAC地址


我的程序在离线时和连接到不同网络时显示不同的Mac地址。有任何想法是为什么? - mrid

1

0

您可以为exe创建安全约束,例如:

  1. 通过提供唯一密码
  2. 通过输入序列号即许可证密钥,只有您知道或基于系统创建随机序列号生成器。

我认为用这种方式,我每次都需要自己安装程序。 - mohammed elshoraky

0

您可以使用硬件ID来识别应用程序的用户,从而允许仅一个用户运行您的程序,或者您可以使用许可证系统。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接