c# - 如何让exe文件只在一台电脑上运行

标签 c# winforms exe

我使用 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# Get Computer's MAC address "OFFLINE"

关于c# - 如何让exe文件只在一台电脑上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35914378/

相关文章:

python - !EXE Tkinter 问题 : datas are LOST when I quit the program

c# - 使用 Bootstrap Datepicker 选择 future 日期并将其传递给 ASP.NET MVC Controller

c# - Task.IsCompleted 使用缓存标志的原因是什么?

c# - 在 winform 中获取控件的父级

c# - 如何从 .Net 窗口应用程序读取 web.config

c++ - 文件能否同时是可执行文件 (EXE) 和动态链接库 (DLL)?

visual-c++ - 如何将 msvc exe 项目转换为 dll 项目?

c# - 有没有像这样的基于元数据声明生成 UI 的库>>?

c# - Automapper 在映射 1400 条记录时运行速度极慢

c# - 如何检查datagridview中的Checkbox是否被选中