This is a mirror of official site: http://jasper-net.blogspot.com/

Mapping VolumeID to Disk partition Using the DeviceIOControl API

| Sunday, March 21, 2010
To map a volume with drive letter to disk partition, one may use some combination of WMI classes like

Win32_LogicalDisk,Win32_LogicalDiskToPartition,Win32_DiskPartition, Win32_DiskDriveToDiskPartition and Win32_DiskDrive.

Unfortunately WMI does not provide a way to map a disk partition that does not have a drive letter associated with it.  There is no WMI class  to associate a disk volume to disk partition directly.  However, one can use the low level DeviceIoControl API to request disk partition information directly from the disk device driver.

Below is a sample program to list all the volumeIDs with corresponding partitions and steps to build the sample using WDK.

1) Download and install the WDK from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=36a2630f-5d56-43b5-b996-7633f2ec14ff
2) Start a command prompt and go to the bin directory in WinDDK installtion folder and run setenv.bat for whatever system you are building for, for example:

setenv C:\WinDDK\7268.0.0 chk WNET

3)  At this point you have a build environment pointing to the WDK install folders created within the CMD window.
4)  Create a folder named 'mounts'  in the build environment folder created in step 3 (in this example C:\WinDDK\7268.0.0) and create following files in it

               * A Header file named 'enumvol.h' using the code snippet given below under enumvol.h header
               * A 'C' source file named 'mounts.c' using code snippet given below under 'mounts.c'header
               * A 'MakeFile' file named 'MakeFile'using the text given under header 'MakeFile' header
               * A 'Source' file named 'Source'using the text given under 'Source'header

5) Navigate to the folder created in step 4  and run “bcz”, this will create an executable file that will display the disk partition information.

Read more: Developer Support ADSI, WMI, Powershell Team Blog

Posted via email from jasper22's posterous

0 comments: