Solved

GET_PARTITION_INFO in Windows NT

Posted on 1997-02-10
1
776 Views
Last Modified: 2013-12-04
I've got a program:
      partitionHandle = CreateFile("\\\\.\\C:",
            0,
            FILE_SHARE_WRITE,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);
      
      if(partitionHandle == INVALID_HANDLE_VALUE)
      {
            AfxMessageBox("Can't open RAID device",
                  MB_OK, 0);
            return;
      }


      if(!DeviceIoControl(partitionHandle,
            IOCTL_DISK_GET_PARTITION_INFO,
            NULL,
            0,
            &partitionInfo,
            sizeof(PARTITION_INFORMATION),
            &regResult,
            NULL))
      {
            
FormatMessage(
    FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,
    GetLastError(),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
    raidRoot,
    64,
    NULL);

            
            
            AfxMessageBox("Can't get RAID info",
                  MB_OK, 0);
            CloseHandle(partitionHandle);      
            return;
      }
      
Now what I got in a msg.string is "Access denied".
I've tried to run it as Administrator with same result.
So what's wrong or/and how could I get partition info in
Windows NT?
0
Comment
Question by:ILIIA
1 Comment
 
LVL 11

Accepted Solution

by:
mikeblas earned 50 total points
ID: 1298760
You need to pass GENERIC_READ to CreateFile().

The documentation implies that you can query the device driver by using 0 for the dwDesiredAccess parameter, and that's true.  But the thing is that the disk driver will end up needing to read the physical device to answer your query, so you need to make sure the handle you pass has adequate access.

I think you should use FILE_SHARE_WRITE | FILE_SHARE_READ, by the way, instead of locking the drive for writes.

Finally, your code is leaky: if you successfully read the information, you never close the handle you created.  You need to CloseHandle() wether the DeviceIOControl() call failed or not.

.B ekiM

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now