I am frantically searching for a source sample, that enumerates all disc
devices ( like CDROM or DVD ). Additionally, if the devices are mounted
inside the NTFS tree ( e.g. c:\devices\mycdrom\ ) , i need the path where
they are mounted.
As an example , the output that MOUNTVOL (cmd-line-tool) gives you would be
enough.
Has anyone an idea how this will work ? I searched the platform SDK for
SetupDi functions, but all my tests were not successful.
with kind regards
Carsten Pohl
John
the setupapi SPDRP_PHYSICAL_DEVICE_OBJECT_NAME
property, returns the name of the physical device object (PDO).
the target of the DosDevices symbolic link on the other hand,
is actually the named *functional* device object (FDO) in the
device stack, with which the filesystem is associated with, so
you won't be able to match those names.
if you want to locate the device that is associated with a given drive
letter mount point, you will need to match the volume names
associated with a device's volume device interface, and a drive letter
mount point.
first, enumerate all existing drive letter mountpoints, and use the
GetVolumeNameForVolumeMountPoint API to find their unique
volume names (in the form \\?\Volume{GUID}\).
Enumerating Mount Points:
http://msdn.microsoft.com/library/en-us/fileio/base/enumerating_mount_points.asp
GetVolumeNameForVolumeMountPoint:
http://msdn.microsoft.com/library/en-us/fileio/base/getvolumenameforvolumemountpoint.asp
next, enumerate all volume device interfaces, using
SetupDiGetClassDevs:
SetupDiGetClassDevs:
http://msdn.microsoft.com/library/en-us/devio/base/setupdigetclassdevs.asp
use the device interface class GUID_DEVINTERFACE_VOLUME, and
specify the DIGCF_PRESENT and DIGCF_DEVICEINTERFACE flags
to constrain the set to only device interfaces that are currently
enabled.
enumerate the list of interfaces in the set with:
SetupDiEnumDeviceInterfaces
http://msdn.microsoft.com/library/en-us/install/hh/install/di-rtns_1cky.asp
and retrieve detailed data for each enumerated interface with:
SetupDiGetDeviceInterfaceDetail
http://msdn.microsoft.com/library/en-us/install/hh/install/di-rtns_6ar6.asp
the SP_DEVICE_INTERFACE_DETAIL_DATA structure retrieved
contains a DevicePath field, which will contain the path to the
symbolic
link for the device.
to find out the drive letter associated with each of those volume
device
interfaces, take the device interface DevicePath (i.e. the
\\?\storage#volume...
path), add a trailing "\" character to it, and pass it to
GetVolumeNameForVolumeMountPoint (same API used above) to find
the the unique volume name for that volume (in the form
\\?\Volume{GUID}\).
compare these volume names with the one that corresponds to the drive
letter mount point you found above to find the matching volume.
the matching volume device interface corresponds directly to some
device,
which you were able to retrieve from SetupDiGetDeviceInterfaceDetail
(the underlying device which that device interface is registered for
is the
SP_DEVINFO_DATA parameter returned).
you can use the CM_Request_Device_Eject API to request that a
device be ejected:
CM_Request_Device_Eject:
http://msdn.microsoft.com/library/en-us/install/hh/install/cfgmgrfn_029e.asp
the CM_ APIs operate on DevInst handles, not SP_DEVINFO_DATA
elements. the DevInst handle is stored as DWORD value in the
SP_DEVINFO_DATA structure:
SP_DEVINFO_DATA:
http://msdn.microsoft.com/library/en-us/install/hh/install/di-struct_7nqq.asp
i'm can't remember if the volume associated with a flash card is
really the
device you'll need to eject here, or if the ejectable device is really
an
ancestor of that device?
if you need to walk up the device tree ancestry for a given device you
can use
the CM_Get_Parent cfgmgr API:
CM_Get_Parent:
http://msdn.microsoft.com/library/en-us/install/hh/install/cfgmgrfn_248i.asp
hope this helps,
jim.
"John" <jbu...@texas.net> wrote in message news:a99cdfdf.03012...@posting.google.com...
> My overall goal is to stop a flash card given a drive letter (E:).
>
> I tried to use QueryDosDevice("E:",buffer, buffersize); to get a
> device name to compare with the device name returned from
> SetupDiGetDeviceRegistryProperty(), but the names do not match. For
> example:
>
> QueryDosDevice returs \Device\Harddisk0\DP(1)0-0+5
>
> SetupDiGetDeviceRegistryProperty with the property set to
> SPDRP_PHYSICAL_DEVICE_OBJECT_NAME returns \Device\PCCard0-1
>
> I seem to be missing a step in the process. Could you possibly point
> me in a direction for my search? You would be my hero for the week!
>
> Thanks John
Carsten Pohl <c...@rstenpohl.de> wrote in message news:<blz0ew5nnjhm$.1cq66jlk2x2rw$.d...@40tude.net>...