Solved

GET_PARTITION_INFO in Windows NT

Posted on 1997-02-10
1
782 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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