简体   繁体   中英

how to make exe file work on one computer only

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

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"

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

u can create the security constrain for exe like

  1. by Giving unique password
  2. By Entering the serial Key ie Licence Key which will know to u only or create random serial key generator based on the system.
  1. 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 ).
  2. 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"
  3. in your c# code, check to see if the computers MAC address matches the 'allowed' MAC address.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM