获取处理器 ID 或某些硬件信息的最安全方法

发布于 2024-10-10 02:04:22 字数 1085 浏览 0 评论 0原文

我需要获取任何信息来识别一台机器,到目前为止我所使用的内容如下:

    internal static string GetProcessorId()
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            using (System.Management.ManagementClass theClass = new System.Management.ManagementClass("Win32_Processor"))
            {
                using (System.Management.ManagementObjectCollection theCollectionOfResults = theClass.GetInstances())
                {
                    foreach (System.Management.ManagementObject currentResult in theCollectionOfResults)
                    {
                        sb.Append(currentResult["ProcessorID"].ToString());
                    }
                }
            }
            return sb.ToString();
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.Message);
            return "";
        }
    }

但是当我在 Windows XP 上(从虚拟机)上运行它时,我的 currentResult["ProcessorID"]null。我不确定是否是因为我使用的是虚拟机,但可能是因为是XP。无论如何,我不太信任这段代码。足够安全吗?我应该通过其他方式获取计算机 ID 吗?这是我正在开发的许可系统的一部分。

I need to get any info to identify a machine and what I was using so far was the following:

    internal static string GetProcessorId()
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            using (System.Management.ManagementClass theClass = new System.Management.ManagementClass("Win32_Processor"))
            {
                using (System.Management.ManagementObjectCollection theCollectionOfResults = theClass.GetInstances())
                {
                    foreach (System.Management.ManagementObject currentResult in theCollectionOfResults)
                    {
                        sb.Append(currentResult["ProcessorID"].ToString());
                    }
                }
            }
            return sb.ToString();
        }
        catch (Exception exception)
        {
            Console.WriteLine(exception.Message);
            return "";
        }
    }

But when I run this on Windows XP (from a Virtual Machine), my currentResult["ProcessorID"] is null. I'm not sure if it is because I'm using a virtual machine, but it might be because is XP. Anyway, I'm not very trustful of this code. Is it safe enough? Should I get a computer Id some other way? This is all part of a licensing system I'm developing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云胡 2024-10-17 02:04:22

对于我编写的一个小工具(Windows Forms .NET 2.0),我需要类似的东西。

我编写了一个帮助程序类,它通过GetVolumeInformation函数的PInvoke简单地使用一些常见信息,例如HDD序列号。

这绝不是真正安全或防弹的,但足够准确以满足我的需求。

(如果您有兴趣,这个就是这个工具,如果我可以链接到的话)

For a small tool I wrote (Windows Forms .NET 2.0), I needed something similar.

I wrote a helper class that simply uses some common information like HDD serial number through PInvoke of the GetVolumeInformation function.

This is by no way really safe or bullet-proof, but accurate enough to fit my needs.

(If you are interested this is the tool, if I'm allowed to link to)

铃予 2024-10-17 02:04:22

即使它有效,也不会达到您想要的效果。 ProcessorID 为您提供过程产品(具有 Y 和 Z 功能的 Pentium X)的标识,而不是有关 CPU 的特定实例的标识。是这样描述的:

描述处理器信息
处理器功能。对于 x86
CPU 类,字段格式取决于
CPUID的处理器支持
操作说明。如果指令是
支持,该属性包含2
(二)DWORD 格式的值。这
第一个是 08h-0Bh 的偏移量,其中
是CPUID的EAX值
指令返回并设置输入 EAX
到 1。第二个是偏移量
0Ch-0Fh,这是 EDX 值
指令返回。只有
该属性的前两个字节是
重要并包含内容
CPU 复位时 DX 寄存器的值 — 所有
其他设置为 0(零),并且
内容为 DWORD 格式。

IBM PC 硬件没有任何防伪硬件标识。

Even if it worked, it wouldn't do what you want. The ProcessorID gives you an identification of the process product (Pentium X with features Y and Z), not about the specific instance of the CPU. It is described thus:

Processor information that describes
the processor features. For an x86
class CPU, the field format depends on
the processor support of the CPUID
instruction. If the instruction is
supported, the property contains 2
(two) DWORD formatted values. The
first is an offset of 08h-0Bh, which
is the EAX value that a CPUID
instruction returns with input EAX set
to 1. The second is an offset of
0Ch-0Fh, which is the EDX value that
the instruction returns. Only the
first two bytes of the property are
significant and contain the contents
of the DX register at CPU reset—all
others are set to 0 (zero), and the
contents are in DWORD format.

The IBM PC hardware doesn't have any kind of fake-proof hardware identification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文