Drive Volume Serial Number

  • Thread starter Thread starter misc
  • Start date Start date
M

misc

Does anyone know how to access the Volume Serial Number of a drive
using .NET? It is easily done in VB6 using the FilingSystemObject. I
appreciate any insight into the matter.
 
Use the WMI managed objects in .Net. Here is a sample to get the volume
serial number for the 'C' drive:

System.Management.ObjectQuery q = new ObjectQuery("select * from
Win32_LogicalDisk where name = 'c:'");
ManagementObjectSearcher s = new ManagementObjectSearcher(q);
foreach (ManagementObject share in s.Get())
{
Console.WriteLine(share["VolumeSerialNumber"]);
}

Sujit D'Mello
 
Thanks for the quick response. I'm fairly new to this. Do you have a
more specific VB.NET sample?

Use the WMI managed objects in .Net. Here is a sample to get the volume
serial number for the 'C' drive:

System.Management.ObjectQuery q = new ObjectQuery("select * from
Win32_LogicalDisk where name = 'c:'");
ManagementObjectSearcher s = new ManagementObjectSearcher(q);
foreach (ManagementObject share in s.Get())
{
Console.WriteLine(share["VolumeSerialNumber"]);
}

Sujit D'Mello
Does anyone know how to access the Volume Serial Number of a drive
using .NET? It is easily done in VB6 using the FilingSystemObject. I
appreciate any insight into the matter.
 
Back
Top