简体   繁体   中英

APIs in C# for grabbing CPU IDs and drive/volume serial

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

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

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).

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?

For CPUID, try this: http://devpinoy.org/blogs/cvega/archive/2006/04/07/2658.aspx

For Volume Serial Number, try this: http://www.eggheadcafe.com/articles/20021019.asp

Google is your friend ;-)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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