PDA

View Full Version : How to get the drive letter using Physical address??



Gokulnathvc
2nd May 2011, 13:35
How to get the drive letter with physical address like "\\\\.\\PHYSICALDRIVE0"?

squidge
2nd May 2011, 15:38
You use the Windows API (eg. WMI). As far as I'm aware, Qt has nothing like this.

Gokulnathvc
3rd May 2011, 05:58
Yes I am using window API. How to perform this in order to get the drive letter with the provided physical address?

squidge
3rd May 2011, 08:11
Like I said, one way would be to use WMI.

How to use WMI is beyond the scope of this forum. A better forum would be one which specialises in the Windows API.

ChrisW67
3rd May 2011, 08:37
Your question is not trivial. A physical drive can contain zero, one, or more Windows volumes or, indeed, only part of one or more Windows volumes. A Windows volume may exist on the physical drive but have no drive letter.

If you don't know how the Windows API, particularly WMI, then it is best you start by reading Microsoft's documentation (http://lmgtfy.com/?q=windows+wmi). Then, if you still cannot work it out, ask your question somewhere there is likely to be some expertise in Windows API intricacies.

Here are a few pages from a straightforward Google search:
http://msdn.microsoft.com/en-us/library/aa394592(v=vs.85).aspx
http://www.activexperts.com/activmonitor/windowsmanagement/adminscripts/disk/drives/#EnumPhysicalDiskDrive.htm

The second one contains a WMI script that outputs this on one on my test machines:


Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

VBOX HARDDISK (\\.\PHYSICALDRIVE0)
Disk #0, Partition #0
C:
VBOX HARDDISK (\\.\PHYSICALDRIVE1)
Disk #1, Partition #0
D:

Gokulnathvc
3rd May 2011, 08:44
I have used this in VC application. But am getting the c: drive only in strDevName .If a particular drive is chosen. List of all drives will be in strDrives. I want to get the drive letter for the corresponding drive number?? please help me..


CString strDrives;
char Drives1 [ 200 ];
memset(Drives1,'\0',200);
GetLogicalDriveStrings(200, Drives1);
int i=0;
char st [ 100 ];
CString strDevName;
strDevName="\\\\.\\";

while (i<DevNum)
{
strcpy(st,Drives1+i);
strDrives += st;
strDevName +=st;
i+= strlen(st);
i+=3;
}
strDevName.Delete(6);

ChrisW67
3rd May 2011, 08:55
Read the thread again. You are asking a Windows API specific question in a Qt forum. Your example code is Microsoft specific classes and API calls. Asking the question again and again will not change the fact that this is the wrong place for your question.