Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Getting Volume Information: Using Win32 System Services

Author: DevASP
Download Source Code : 633_VolumeInfo src.zip

You can obtain information about any volume available locally on your machine or mounted over the network using the Win32 System Services API GetVolumeInformation .

The signature of this function looks like this.

GetVolumeInformation

                                    Returns information about a drive

 

 

BOOL GetVolumeInformation(

   LPTSTR rootName,

   LPTSTR volumeName,

   DWORD volumeNameSize,

   LPDWORD volumeSerialNumber,

   LPDWORD maximumNameLength,

   LPDWORD fileSystemFlags,

   LPTSTR fileSystemName,

   DWORDfileSystemNameSize);

 

RootName                                 The name of the logical drive

VolumeName                             The name of the volume

VolumeNameSize                      Size of the volume name

VolumeSerialNumber                  Volume serial number

MaxNameLength                        Maximum length of any file name

FileSystemFlags                        Information flags for the file system

FileSystemName                       Name of the file system (FAT, NTFS, and so on)

FileSystemNameSize                 Size of the file system name

Returns TRUE on success

 

The GetVolumeInformation function returns the volume name and serial number, along with the type of file system used on the volume (FAT, NTFS, HPFS, or other) and the length of the maximum file name for the file system in use on that volume. The function also returns a flag word that gives you characteristics of the file system such as case sensitivity. The following flags are defined:

 

FS_CASE_IS_PRESERVED: The file system saves the case of characterswhen it stores file names on the disk

 

FS_CASE_SENSITIVE: The file system distinguishes uppercase and lowercase characters in file names

 

FS_UNICODE_STORED_ON_DISK: File names support Unicode

 

The sample code added with this article is Get the volume information of C drive on your system.

 

This code looks like this.

 

BOOL success;

      char volumeName[MAX_PATH];

      DWORD volumeSerialNumber;

      DWORD maxNameLength;

      DWORD fileSystemFlags;

      char systemName[MAX_PATH];

 

      // get the volume information for drive C

      success = GetVolumeInformation("c:\\",

            volumeName, MAX_PATH,

            &volumeSerialNumber,

            &maxNameLength,

            &fileSystemFlags,

            systemName, MAX_PATH);

 

     

      MessageBox(volumeName,"Volume Name");

      CString str;

      str.Format("%d",volumeSerialNumber);

      MessageBox(str,"Volume Serial Number");

     

      MessageBox(systemName,"File System Type");

     

      str="";

      str.Format("%d",maxNameLength);

      MessageBox(str,"Maximum File Name Length");

 

     

      if (fileSystemFlags & FS_CASE_IS_PRESERVED)

     

            MessageBox("Case is preserved");

      else

     

            MessageBox("Case Is not Preserved");

 

      if (fileSystemFlags & FS_CASE_SENSITIVE)

     

            MessageBox("Case sensitive");

      else

     

            MessageBox(" Not case sensitive");

 

      if (fileSystemFlags & FS_UNICODE_STORED_ON_DISK)

     

            MessageBox("Unicode stored");

      else

     

               MessageBox("Unicode not stored");

 

The listing above will show you the Volume Name, volume Serial Number, File System Type, Maximum File Name Length, Whether the case is preserved or not, whether the case sensitive or not, whether Unicode stored or not of the Drive “C” on your local hard disk.

Article Comments
dear
your coding is very good but this coding is not working is web application plz tell me why or send the coding asp.net thanks is Advance
your Best Friend
Asif Ali Memon

Posted on 3/9/2007 3:21:41 AM by Asif Ali Memon

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How can we Lock Files.

Disclaimer - Privacy
© 2002-2017 DevASP.net