I'd like to retrieve the Disk ID of my hard drive using C#.
I do not want "SerialNumber" as most articles talked since it's absent on my box.
To check this ID , you can run "cmd" on windows:
diskpart
list disk
select disk 0
detail disk
The output is like:
HGST HTS725050A7E630
Disk ID: 1033D54D
...
On my virtual box the output is
VBOX HARDDISK
Disk ID: 22452244
The disk ID seems to be a 32bit integer.
Is there anyway to get the same thing using C# (using API instead of parsing cmd output)?
This value is stored as the 'Signature'. You get this the same place that you get the Serial Number.
ManagementObjectSearcher win32DiskDrives = new ManagementObjectSearcher("select * from Win32_DiskDrive");
foreach (ManagementObject win32DiskDrive in win32DiskDrives.Get())
{
Console.WriteLine("{0:X}", win32DiskDrive.Properties["Signature"].Value);
}
You could use WMI and the Win32_DiskDrive class. There are both a DeviceID
and a SerialNumber
properties, you might want to check if it contains the value you're looking for.
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.