Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get physical drive from "\Device\HarddiskVolume1"?

3,449 views
Skip to first unread message

dont_spa...@yahoo.com

unread,
May 26, 2005, 1:16:35 PM5/26/05
to
The SystemDevice property of Win32_OperatingSystem returns something
like "\Device\HarddiskVolume1". I don't see this format anywhere else
in WMI. What is it, and how can I use it to obtain the underlying
physical device such as "\\.\PHYSICALDRIVE0"?

Here's some background: what I really need is a fast way to get from a
drive letter such as C: to the WMI properties of the underlying
physical drive (Model, Signature, etc.) I currently do this by
navigating through Win32_LogicalDiskToPartition and
Win32_DiskDriveToDiskPartition, but it's unacceptably slow for our
purposes (more than a second). Now, an API call to QueryDosDevice gets
me from C: to \Device\HarddiskVolume1 really quickly. All I need now
is a fast way to get from there to PHYSICALDRIVE0 and then I'm home
free. Or just a fast way to get there from C: in the first place :)

Any help would be greatly appreciated.

Daniel

Jan Peter Stotz

unread,
May 27, 2005, 5:01:00 AM5/27/05
to
dont_spa...@yahoo.com schrieb:

> Win32_DiskDriveToDiskPartition, but it's unacceptably slow for our
> purposes (more than a second). Now, an API call to QueryDosDevice gets
> me from C: to \Device\HarddiskVolume1 really quickly. All I need now
> is a fast way to get from there to PHYSICALDRIVE0 and then I'm home
> free.

If you already use the Win32-API I would recommend to use first
GetVolumeNameForVolumeMountPoint() to acquire the internal volume name.
Remove the backslash at the end and use it with CreateFile() to get a
handle of the volume. Use the handle with
DeviceIoControl(volumeHandle,IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,...)

After that you have the physical drive(s) numbers (a partition may me span
more that one physical drive). Prepend "\\.\PHYSICALDRIVE" to the drive
number and you have what you want.

Jan

dont_spa...@yahoo.com

unread,
May 27, 2005, 1:11:14 PM5/27/05
to
Jan,

Thank you very much. I set about following your instructions, but ran
into the following in the MSDN documentation for CreateFile: the caller
must have administrative privileges in order to open a volume.
Unfortunately, most of our users do not have administrative privileges.

Is there another way?

Thanks again,
Daniel

Gerry Hickman

unread,
May 27, 2005, 6:15:09 PM5/27/05
to
dont_spa...@yahoo.com wrote:

> must have administrative privileges in order to open a volume.
> Unfortunately, most of our users do not have administrative privileges.

It's a bit worrying if non-Admin users need direct access to physical
drives!

--
Gerry Hickman (London UK)

dont_spa...@yahoo.com

unread,
May 28, 2005, 2:57:10 AM5/28/05
to
> It's a bit worrying if non-Admin users need direct access to physical drives!

They don't, of course, and this is quite beside the point. The question
is simply how to get the /path/ of the physical drive given a drive
letter. (The standard way via WMI is too slow to be useful in the
present case.) The ultimate goal is to read a couple of hardware
properties (such as serial number) suitable for anchoring a software
license to a particular PC.

Jan helpfully suggested a series of API calls that would do the trick.
Unfortunately, since CreateFile appears to require admin rights, I
can't use this precise sequence. I hope there is another sequence that
can work (possibly via the DOS device name mentioned in the subject
header). Your suggestions to this effect would be most welcome.

Daniel

Jim Vierra

unread,
May 29, 2005, 1:53:51 AM5/29/05
to
Have you looked into using DRM for anchoring a software license. This is
one of the reasons it was created.


--
Jim Vierra

<dont_spa...@yahoo.com> wrote in message
news:1117263430.3...@g47g2000cwa.googlegroups.com...

dont_spa...@yahoo.com

unread,
May 30, 2005, 1:28:05 PM5/30/05
to
> Have you looked into using DRM for anchoring a software license

I looked at it but it seems designed for streaming audio/video and
looks pretty complicated.

The company I'm working with already has a licensing solution; the
trouble is that it takes > 1 second to match the license against the
hardware it's running on, hence my search for a fast way to identify
which physical drive is associated with a drive letter.

Daniel

Jim Vierra

unread,
May 30, 2005, 4:39:19 PM5/30/05
to
Anything can be put under DRM from what I have seen, It is designed to
support streaming and other forms of licensing.

See RMS here
http://www.microsoft.com/resources/documentation/windowsserv/2003/all/rms/en-us/InitExp_4.mspx

You can also use Software Policies in GP to manage software usage by host
and by user. It's as granular as you want it to be.

--
Jim Vierra

<dont_spa...@yahoo.com> wrote in message
news:1117474085.6...@z14g2000cwz.googlegroups.com...

Gerry Hickman

unread,
May 31, 2005, 6:02:09 PM5/31/05
to
Jim Vierra wrote:

> Anything can be put under DRM from what I have seen, It is designed to
> support streaming and other forms of licensing.

Anyone who attempts to put a DRM lock on their software deserves to have
it broken. One of the main problems with DRM is that it usually ends up
locking out the legitimate user when they change their hardware, while
the hacked version carries on working for years.

Jim Vierra

unread,
May 31, 2005, 8:55:18 PM5/31/05
to
Nonsense. We are talking about a centralized Rights Management Server and
no a digital key. Classic DRM has that problem if you don't back up your
key store. Things like IPODs have a problem because they have to be tied to
a service to work. Software keys using RMS can allow you to move the key.

The issue in most cases is proving to a vendor that you can control
distribution. If you have a legitimate system for this and the software is
key driven then I would think RMS would make managing use very much easier.
The ability to report usage would be valuable in many cases.


--
Jim Vierra

"Gerry Hickman" <gerry...@yahoo.co.uk> wrote in message
news:eDqvOxiZ...@TK2MSFTNGP12.phx.gbl...

CHarris

unread,
Jun 9, 2005, 2:30:46 PM6/9/05
to
Hello Dan, I am currently interested in seeing your code. I am currently
trying to do something similar, like detecting a new device coming in and
getting it's properties, and going backwards for when the program starts up.

So I need:
\\.\PHYSICALDRVIE2 -> G:\
and
G:\ to \\.\PHYSCICALDRIVE2

However, I am kind of stumped. Your code would really help me a lot.
Please e-mail me at qbasicer[a-t]]gmail[d-o-t]]com

Gene

unread,
Feb 11, 2008, 8:33:46 PM2/11/08
to
I've just solved the same problem, given \Device\CdRom0 I need D:

QueryDosDevice() converts D: to \Device\CdRom0 so I iterate from A: to Z:
until I get a match on the device name:

for (char disk = 'A'; disk <= 'Z'; ++disk) {
string diskPath = string(&disk, 1) + ":";
WCHAR buf[1000];
if (QueryDosDevice(Utf16String(diskPath), buf, 1000) != 0) {
string device = Utf16String(buf).str();
if (device == drive.device) {
drive.drive = diskPath;
break;
}
}
}

url:http://www.ureader.com/msg/1486258.aspx

hejun

unread,
Mar 24, 2008, 4:27:55 AM3/24/08
to
0 new messages