如何使exe文件仅在一台计算机上工作 [英] how to make exe file work on one computer only

查看:114
本文介绍了如何使exe文件仅在一台计算机上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C#编写了一个程序,并使用高级安装程序制作了exe文件,它很好用,但是我想使此exe文件在一台计算机上工作,因为有些局限 以exe并将这个exe交给其他人,我想对其进行保护并保护我的作品

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

推荐答案

在需要.exe的计算机上运行以下代码.文件进行处理(它将为您提供这台机器的MAC地址). 2.将此MAC地址添加到下面的代码中 3.将以下代码添加到您的C#代码中,以确保它仅在具有正确MAC地址(唯一)的计算机上运行

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;
        }


    }
}

参考: C#获取计算机的MAC地址"OFFLINE"

这篇关于如何使exe文件仅在一台计算机上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆