Click here to Skip to main content
13,350,483 members (68,300 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 20 Dec 2007

Getting Drive's Volume Information using C#

, 20 Dec 2007
Rate this:
Please Sign up or sign in to vote.
Getting Drive's Volume Information using C#


First of all, I want to say sorry for my poor English. In this article, I try to explain how to get the volume information of our logical drives by using kernel32.dll.


This DLL supports capabilities that are associated with OS such as:

  • Process loading
  • Context switching
  • File I/O
  • Memory management


This function is used to get the volume information of drive. It gives serial number, volume name and file type.

The following is the declaration of GetVolumeInformation function:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern bool GetVolumeInformation(string Volume, StringBuilder VolumeName, 
	uint VolumeNameSize, out uint SerialNumber, out uint SerialNumberLength, 
	out uint flags, StringBuilder fs, uint fs_size);

DllImport is used to import the kernel32.dll file. The out variable SerialNumber will return the serial number of a given drive. Here, the following code will explain how to get volume information of a given drive.

uint serialNum, serialNumLength, flags;
StringBuilder volumename = new StringBuilder(256);
StringBuilder fstype = new StringBuilder(256); 

bool ok = = GetVolumeInformation(drives, volumename, 
	(uint)volumename.Capacity - 1, out serialNum, out serialNumLength, 
	out flags, fstype, (uint)fstype.Capacity - 1);

if (ok)
  lblVolume.Text = lblVolume.Text + "\n Volume Information of " + drives + "\n";
  lblVolume.Text = lblVolume.Text + "\nSerialNumber of is..... " + 
	serialNum.ToString() + " \n";
   if (volumename != null)
   lblVolume.Text = lblVolume.Text + "VolumeName is..... " + 
	volumename.ToString() + " \n";
if (fstype != null)
 lblVolume.Text = lblVolume.Text + "FileType is..... " + fstype.ToString() + " \n";

Hope this will help you. :)


  • 20th December, 2007: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Web Developer
India India
Hi Viewers,

I wish to all. This is Vinoth. This is where I try to condense everything that you need to know about me.


visit my blog


I'm passionate about a great many things and continually learning about the things that interest me. They are wearable computers, User Interface Design, Artificial life, Industrial music.

You may also be interested in...


Comments and Discussions

Questionget volume label Pin
vdeo112-Dec-13 20:21
membervdeo112-Dec-13 20:21 
GeneralMy vote of 5 Pin
ArmandoHeck13-Feb-13 6:20
memberArmandoHeck13-Feb-13 6:20 
GeneralSystem.IO.DriveInfo Pin
Daniele Rota Nodari18-Jul-12 0:30
memberDaniele Rota Nodari18-Jul-12 0:30 
GeneralRe: System.IO.DriveInfo Pin
ocelot24-Feb-13 21:16
memberocelot24-Feb-13 21:16 
SuggestionRe: System.IO.DriveInfo Pin
Daniele Rota Nodari24-Feb-13 22:35
memberDaniele Rota Nodari24-Feb-13 22:35 
GeneralMy vote of 5 Pin
terenyang26-Oct-11 0:02
memberterenyang26-Oct-11 0:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 21 Dec 2007
Article Copyright 2007 by S.Vinothkumar
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid