Drive serial number

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi,
I need a way to get the serial number for a hard drive. Is there a way to do
this using the .NET framework?
Any help would be appreciated.
 
Andrew,
Thanks for the post. I already looked into the WMI32_PhysicalMedia class -
looks like it only works under XP and I cannot limit the user base to XP.
Any other suggestions?

Tony
 
Tony,

You can use the native GetVolumeInformation API using p/invoke.

Here is its method signature.

DllImport("kernel32.dll", CharSet=CharSet.Auto)]
private static extern long GetVolumeInformation(string PathName,
StringBuilder VolumeNameBuffer, UInt32 VolumeNameSize, ref UInt32
VolumeSerialNumber, ref UInt32 MaximumComponentLength, ref UInt32
FileSystemFlags, StringBuilder FileSystemNameBuffer, UInt32
FileSystemNameSize);

Good luck!

-Andrew
 
Last I checked, GetVolumeInformation returned the "volume serial number",
not the "hard drive serial number".

Has WMI been modified in Win XP to return the hard drive serial number?
Last I checked, in Win 2000, it returned only the volume serial number.
 
WMI on WinXP can return the physical device serial number, using the
WMI32_PhysicalMedia class. And your right about GetVolumeInformation, it
will return the serial number for the volume when it was created/formated.

It IS possible to get the serial number of an IDE drive using the
DeviceIoControl API in kernel32, if WMI isn't an option.

-Andrew
http://abaum.com/blog
 
Back
Top