简体   繁体   English

如何在C#中生成系统(PC /笔记本电脑)硬件唯一ID?

[英]How to generate a System (PC/Laptop) Hardware unique ID in C#?

How to generate a System( PC/Laptop) Hardware unique ID in C#? 如何在C#中生成系统(PC /笔记本电脑)硬件唯一ID?

Please Note: The configuration is same for all the systems. 请注意:所有系统的配置都相同。

您可以使用Guid类和NewGuid方法:

var uniqueId = Guid.NewGuid();

Generally one of the most reliable approaches is to see if you can't grab the MAC address of a network card. 通常,最可靠的方法之一是查看是否无法获取网卡的MAC地址。 Generally these are unique (unless you also configured all your MAC addresses to be the same in which case you will have bigger problems :)) But I second the earlier comment. 通常这些都是唯一的(除非您还将所有MAC地址配置为相同,在这种情况下您将遇到更大的问题:))但我先说出之前的评论。 If this is for copy protection don't do it. 如果这是复制保护,请不要这样做。 Users will be frustrated when they switch they network cards or retire their PC to move to more recent hardware. 用户在切换网卡或退出PC以转移到更新的硬件时会感到沮丧。

You can generate a GUID not programmatically by using "Microsoft Windows SDK" tool "GUID Generator" ( guidgen.exe ). 您可以使用“Microsoft Windows SDK”工具“GUID生成器”guidgen.exe )以编程方式生成GUID。 This tool has a different ways to represent a generated GUID, so you can further use it right in your application. 此工具有不同的方式来表示生成的GUID,因此您可以在应用程序中进一步使用它。

在此输入图像描述

I guess instead of the MAC address as it's based on the peripheral which can be changed, you can use the Processor & Motherboard id to identify the system as they will be only changed when it's damaged and creates a new system instead when changed 我想而不是MAC地址,因为它基于可更改的外围设备,您可以使用处理器和主板ID来识别系统,因为它们只会在损坏时更改,并在更改时创建新系统

Func<string> SystemId = () =>
    {
        ManagementObjectCollection mbsList = null;
        ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
        mbsList = mbs.Get();
        string id = "";
        foreach (ManagementObject mo in mbsList)
        {
            id = mo["ProcessorID"].ToString();
        }

        ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
        ManagementObjectCollection moc = mos.Get();
        string motherBoard = "";
        foreach (ManagementObject mo in moc)
        {
            motherBoard = (string)mo["SerialNumber"];
        }

        string uniqueSystemId = id + motherBoard;
        return uniqueSystemId;
    };

    Console.WriteLine(SystemId());

Even processor can be updated so that can be ignored + i got to know even Microsoft used to have the motherboard id to identify/activate windows. 甚至处理器也可以更新,以便可以忽略+我知道甚至微软曾经拥有主板ID识别/激活窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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