在 Windows 上生成硬件 ID

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/910619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:33:11  来源:igfitidea点击:

Generating a Hardware-ID on Windows

c++windowsuniqueuuidcopy-protection

提问by Patrick Glandien

What is the best way to generate a unique hardware ID on Microsoft Windows with C++ that is not easily spoofable (with for example changing the MAC Address)?

在 Microsoft Windows 上使用 C++ 生成不易被欺骗的唯一硬件 ID(例如更改 MAC 地址)的最佳方法是什么?

采纳答案by AgileJon

Windows stores a unique Guid per machine in the registry at:

Windows 将每台机器的唯一 Guid 存储在注册表中:

HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\MachineGuid

回答by Michael Haephrati

This used to be the CPU serial number but today there are many types of motherboards and this factor is not accurate. MAC address can be easily forged. That leaves us with the internal hard drive serial number. See also: http://www.codeproject.com/Articles/319181/Haephrati-Searching-for-a-reliable-Hardware-ID

这曾经是 CPU 序列号,但今天有许多类型的主板,这个因素并不准确。MAC地址很容易被伪造。这给我们留下了内部硬盘驱动器序列号。另见:http: //www.codeproject.com/Articles/319181/Haephrati-Searching-for-a-reliable-Hardware-ID

回答by Emilio Garavaglia

There are a variety of "tricks", but the only real "physical answer" is "no, there is no solution".

有各种各样的“技巧”,但唯一真正的“物理答案”是“不,没有解决方案”。

A "machine" is nothing more than a passive bus with some hardware around. Although each piece of iron can provide a somehow usable identifier, every piece of iron can be replaced by a user for whatever bad or good reason you can never be fully aware of (so if you base your functionality on this, you create problems to your user, and hence -as a consequence- to yourself every time an hardware have to be replaced / reinitialized / reconfigured etc. etc.).

“机器”只不过是带有一些硬件的无源总线。尽管每块铁块都可以提供某种可用的标识符,但每块铁块都可以由用户更换,无论出于什么坏或好的原因,您永远无法完全意识到(因此,如果您将功能建立在此基础上,则会给您的系统带来问题)用户,因此 - 结果 - 每次必须更换/重新初始化/重新配置硬件等时,您自己)。

Now, if your problem is identify a machine in a context where many machines have to inter-operate together, this is a role well played by MAC or IP addresses or Hostnames. But be prepared to the idea that they are not necessarily constant on long time-period (so avoid to hard-code them - instead "discover then" upon any of your start-up)

现在,如果您的问题是在许多机器必须一起互操作的上下文中识别一台机器,那么 MAC 或 IP 地址或主机名可以很好地发挥这一作用。但是要准备好接受它们不一定在很长一段时间内保持不变的想法(因此避免对它们进行硬编码 - 而是在您的任何启动时“然后发现”)

If your problem is -instead- identify a software instance or a licence, you have probably better to concentrate on another kind of solution: you sell licences to "users" (it is the user that has the money, not his computer!), not to their "machines" (that users must be free to change whenever they need/like without your permission, since you din't licence the hardware or the OS...), hence your problem is not to identify a machine, but a USER (consider that a same machine can be a host for many user and that a same user can work on a variety of machines ..., you cannot assume/impose a 1:1 relation, without running into some kind of problems sooner or later, when this idiom ifs found to no more fit).

如果您的问题是 - 而不是 - 识别软件实例或许可证,您可能最好专注于另一种解决方案:您将许可证出售给“用户”(有钱的是用户,而不是他的计算机!),不是他们的“机器”(用户必须在未经您许可的情况下在他们需要/喜欢的时候自由更改,因为您没有许可硬件或操作系统......),因此您的问题不是识别机器,而是一个用户(考虑到同一台机器可以是许多用户的主机,并且同一个用户可以在不同的机器上工作......,你不能假设/强加 1:1 的关系,否则很快就会遇到某种问题或稍后,当发现这个习语不再合适时)。

The idea should be to register the users in a somewhat reachable site, give them keys you generate, and check that a same user/key pair is not con-temporarily used more than an agreed number of times under a given time period. When violations exceed, or keys becomes old, just block and wait for the user to renew.

这个想法应该是在一个有点可达的站点上注册用户,给他们你生成的密钥,并检查在给定的时间段内同一个用户/密钥对的同时使用次数没有超过商定的次数。当违规超过或密钥变旧时,只需阻止并等待用户更新。

As you can see, the answer mostly depends on the reason behind your question, more than from the question itself.

如您所见,答案主要取决于问题背后的原因,而不是问题本身。

回答by Migrate2Lazarus see my profile

Here is a program (also available as DLL) that can read and show your computer/hardware ID: http://www.soft.tahionic.com/download-hdd_id/index.html

这是一个可以读取和显示您的计算机/硬件 ID的程序(也可以作为DLL 提供):http: //www.soft.tahionic.com/download-hdd_id/index.html

回答by GalacticCowboy

There are various IDs assigned to hardware that can be read and combined to form a machine key. For example, you could get the ID of the hard drive where the software is stored, the proc ID, etc. Some of these can be set more easily than others, but part of the strength is in combining multiple pieces together that are not necessarily strong enough by themselves.

分配给硬件的各种 ID 可以读取并组合以形成机器密钥。例如,您可以获得存储软件的硬盘驱动器的 ID、进程 ID 等。其中一些设置比其他设置更容易,但部分优势在于将多个部分组合在一起,这些部分不一定是自己足够强大。

回答by GalacticCowboy

Use Win32 System HDS APIs. Don't read the registry, it has no sense at all.

使用 Win32 系统 HDS API。不要阅读注册表,它根本没有任何意义。