C# 中的 API,用于获取 CPU ID 和驱动器/卷序列号

发布于 2024-07-07 22:38:18 字数 292 浏览 5 评论 0原文

我知道我可以通过查询 WMI 来获取物理驱动器的 CPU 标识符和卷序列号,但 WMI 通常需要很长时间。 还有哪些其他更快的选项(如果有)可用于检索此信息? 是否有 Win32 API 可以完成此任务?

编辑:请允许我澄清一下。 对于 CPU 标识符,我指的是通过查询以下 WMI 实例属性获得的相同值:

  • Win32_Processor::ProcessorId
  • Win32_LogicalDisk::VolumeSerialNumber

I'm aware that I can grab the CPU identifier and the volume serial number for a physical drive by querying WMI, but WMI usually takes its sweet time. What other speedier options, if any, are available to retrieve this information? Are there Win32 APIs that would accomplish this?

Edit: Allow me to clarify. By CPU identifier, I'm referring to the same value one gets by querying the following WMI instance properties:

  • Win32_Processor::ProcessorId
  • Win32_LogicalDisk::VolumeSerialNumber

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

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

发布评论

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

评论(4

丢了幸福的猪 2024-07-14 22:38:18

请记住,CPU 的 ID 并不总是可用。

顺便问一下,你想实现什么目标? 如果要为计算机实例生成唯一密钥,请选中生成唯一密钥(Finger Print) for a Computer for Licensing Purposes 由 Sowkot Osman 在 Codeproject 发表; 它可以给你一些提示(也可以阅读评论)。

Just keep in mind that ID of the CPU is not always available.

By the way, what are you trying to accomplish? If you want to generate a unique key for a computer instance, check the Generating Unique Key (Finger Print) for a Computer for Licensing Purposes post by Sowkot Osman at Codeproject; it can give you some hints (also read comments).

剧终人散尽 2024-07-14 22:38:18

您可以在 Windows 注册表中查询驱动器信息,但不确定 CPU 的信息。 看来你的问题在这个SO q/a中得到了解决(演示了多种获取此信息的方法,但为了速度,也许从注册表获取它是你最好的选择)

: com/questions/327718/how-to-list-physical-disks">如何列出物理磁盘?

You can query the windows registry for the drive information, not sure about the CPU though. It seems that your question is addressed in this SO q/a (demonstrates a number of methods to get this info, but for speed, maybe getting it from registry is your best bet):

How to list physical disks?

素衣风尘叹 2024-07-14 22:38:18

WMI 实际上从注册表中获取了很大一部分数据。 该系统存储了大量有关系统的信息,而且响应速度显然非常快。

如果您出于许可原因希望锁定主板、CPU 和/或 HDD,请查看以下值:
HKLM\HARDWARE\DESCRIPTION\System\BIOS\BaseBoardManufacturer
HKLM\硬件\描述\系统\BIOS\BaseBoardProduct
HKLM\硬件\描述\系统\中央处理器\0\标识符
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0\ProcessorNameString
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx
HKLM\HARDWARE\DESCRIPTION\System\MultifunctionAdapter\0\DiskController\0\DiskPeripheral\0
(可能特定于使用 RAID 的主板)

如果您想在没有 WMI 的情况下获取磁盘序列号,请发出 DeviceIoControl调用物理驱动设备。 VB.NET 中的示例代码: http://www.dreamincode.net/code/snippet429.htm< /a>

WMI actually takes a good portion of its data from the registry. The system stores plenty of information in there about the system, and it's obviously very quick to respond.

If you're looking to lock to the motherboard, CPU and/or HDD for licensing reasons, check out the following values:
HKLM\HARDWARE\DESCRIPTION\System\BIOS\BaseBoardManufacturer
HKLM\HARDWARE\DESCRIPTION\System\BIOS\BaseBoardProduct
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0\Identifier
HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0\ProcessorNameString
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductId
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\BuildLabEx
HKLM\HARDWARE\DESCRIPTION\System\MultifunctionAdapter\0\DiskController\0\DiskPeripheral\0
(may be specific to boards with RAID in use)

If you want to get the disk serial without WMI, issue a DeviceIoControl call to the physical drive device. Sample code in VB.NET: http://www.dreamincode.net/code/snippet429.htm

萌面超妹 2024-07-14 22:38:18

我喜欢 GetSystemInfo 但这不包括物理驱动器..

I like GetSystemInfo but that doesn't cover physical drives..

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