如何使exe文件只在一台计算机上工作

时间:2016-03-10 10:51:57

标签: c# winforms exe

我使用C#编写了一个程序并使用高级安装程序生成exe文件,它运行良好,但我想让这个exe文件在一台计算机上运行,​​因为有些clints 拿exe并把这个exe给另一个,我想保护这个并保护我的作品

5 个答案:

答案 0 :(得分:2)

在您想要.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# Get Computer's MAC address "OFFLINE"

答案 1 :(得分:1)

我认为你想要的是某种许可证密钥和授权方法。

快速谷歌出现了这篇文章,你可能会发现它很有用。

http://www.codeproject.com/Articles/28678/Generating-Unique-Key-Finger-Print-for-a-Computer

答案 2 :(得分:0)

你可以为exe创建安全约束

  1. 通过提供唯一密码
  2. 输入序列密钥,即Licence Key ,它只知道您或根据系统创建随机序列密钥生成器。

答案 3 :(得分:0)

  1. 获取您希望.exe文件可以使用的计算机的MAC地址(在Windows类型中:C:\ getmac(请参阅:https://helpdesk.latech.edu/index.php?option=com_content&task=view&id=207&Itemid=67)。
  2. 将以下c#代码添加到您的应用程序中......此代码在每次运行时查找计算机MAC地址:C# Get Computer's MAC address "OFFLINE"
  3. 在您的c#代码中,检查计算机的MAC地址是否与“允许的”字符匹配。 MAC地址。

答案 4 :(得分:0)

您只允许一个用户使用硬件ID运行您的程序,以识别使用该应用程序的用户,或者您可以使用许可系统。

相关问题