DeviceIoControl question
-
My project is to make an app that erases media (HDD, USB flash, USB HDD, etc.) showing some information on them. I use
\\.\PhysicalDrive**X**
to access the media for details on the size and type (fixed, removable, etc.). I found that the registry keyHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\
keeps up-to-date the drives in order that they are attached. First it comes the first HDD - subkey"0"
something likeIDE\DiskWDC_WD5000BEVT-0A0RT0__________________01.01A01\5&2c0d176e&0&0.0.0
, next, the next HDD ... . Then follows the USB devices, in the order that they were attached. Here comes trouble... Consider you have 1 HDD and 2 USB devices A and B. Subkey 0 holds data for the HDD. Attach A, subkey 1 holds data for A. Attach B, subkey 2 holds data for B. Detach A, subkey 1 holds data for B. Attach A, subkey 2 holds data for A. ... and all this time ... A remained\\.\PhysicalDrive**1**
B remained\\.\PhysicalDrive**2**
I can`t count on registry for that information, so I have to obtain them - viaDeviceIoControl
with ahandle
for\\.\PhysicalDrive**X**
so I can map the devices to the description, exactly. I hope that is clear enough, now, what is my problem. :((36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
Hi, Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision' Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^]. If you need to know which physical drive such as
\\.\PhysicalDrive1
then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^]. If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^]. All of this info combined with the Intel sample should give you enough to uniquely identifying drives. Best Wishes, -David Delaune -
Hi, Could you be a little more clear about the exact problem you are having? While I do understand the problem you mention in your last post... I fail to see how this relates to the original post where you stated that you need 'manufacturer, type, revision' Someone asked me a similar question a few years ago. Maybe you will find something useful there. Here is the post[^]. If you need to know which physical drive such as
\\.\PhysicalDrive1
then you should investigate the IOCTL_STORAGE_GET_DEVICE_NUMBER control code[^] and populate a STORAGE_DEVICE_NUMBER structure[^]. If you are having problems identifying the USB device after the user has moved the USB device... maybe you should investigate the IOCTL_STORAGE_GET_MEDIA_SERIAL_NUMBER control code[^] and populate a MEDIA_SERIAL_NUMBER_DATA structure[^]. All of this info combined with the Intel sample should give you enough to uniquely identifying drives. Best Wishes, -David DelauneIn this
App
I useDeviceIoControl
to accomplish the following tasks: - enumerate thePhysicalDrive**X**
devices - determine nr. of bytes to be overwritten - for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to. And all this via aHANDLE
fromCreateFile("\\\\.\\PhysicalDrive**X**", ...)
Everything goes OK forATA
, not forUSB
. In my previous post I have shown an example on how you can`t rely onHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\**N**
because USB devices are presented in the order they were attached. So, the question is: can I obtain with aHANDLE
created byCreateFile("\\\\.\\PhysicalDrive**X**", ...)
data reffering to manufacturer, type, revision for aUSB
attached storage device?36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
In this
App
I useDeviceIoControl
to accomplish the following tasks: - enumerate thePhysicalDrive**X**
devices - determine nr. of bytes to be overwritten - for ATA devices determine the Vendor, Product and Revision http://www.winsim.com/diskid32/diskid32.html[^] [http://www.winsim.com/diskid32/diskid32.html[^]] for the reason that the user not to erase a drive that is not intended to. And all this via aHANDLE
fromCreateFile("\\\\.\\PhysicalDrive**X**", ...)
Everything goes OK forATA
, not forUSB
. In my previous post I have shown an example on how you can`t rely onHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Disk\Enum\**N**
because USB devices are presented in the order they were attached. So, the question is: can I obtain with aHANDLE
created byCreateFile("\\\\.\\PhysicalDrive**X**", ...)
data reffering to manufacturer, type, revision for aUSB
attached storage device?36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
RomTibi, I completely understand your problem now. You have a
HANDLE
to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David Delaune -
RomTibi, I completely understand your problem now. You have a
HANDLE
to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David Delaune:rose:Thank you! I`ll do what you said. Waiting for your answer I found this: http://code.msdn.microsoft.com/CppStorageEnum-90ad5fa9[^] I`ve tested a few, it seem to work, but it is to clean up a lot, maybe to include the dll code in the main. I`ll keep you up to date with my progress. Thanks again! :)
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
RomTibi, I completely understand your problem now. You have a
HANDLE
to a physical drive and want to somehow associate that back to the USB device. I spent about 10 minutes looking into this... and I did not find any way to use DeviceIoControl because there are no documented IOCTL codes that will do this. I did not find any documented methods for using a HANDLE to a physical drive for obtaining information about the parent USB device. However... you can absolutely do this using the Windows SetupAPI[^]. You could call the SetupDiGetClassDevs function[^] with the GUID_DEVINTERFACE_DISK class[^] and enumerate all of the storage devices using SetupDiEnumDeviceInterfaces[^] and call the SetupDiGetDeviceInterfaceDetail function[^] to get the drive path and serial. You can then call the CM_Get_Parent function[^] to get the parent USB device and retrieve these details. Please spend some time researching this... if you cannot figure it out let me know and when I have more free time I may be able to write a sample function for you. Best Wishes, -David DelauneHappy 9 years and 2 days of CodeProject! :) I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull... :(
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
Happy 9 years and 2 days of CodeProject! :) I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull... :(
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
RomTibi wrote:
Happy 9 years and 2 days of CodeProject! :)
Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.
RomTibi wrote:
I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...
Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?
-
RomTibi wrote:
Happy 9 years and 2 days of CodeProject! :)
Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.
RomTibi wrote:
I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...
Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?
I use Windows Platform SDK Feb 2003 http://groups.google.com/group/microsoft.public.platformsdk.sdk_install/msg/087b0178f5d8159e?&hl=en&pli=1[^]
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
RomTibi wrote:
Happy 9 years and 2 days of CodeProject! :)
Thanks! :) I have actually been a member here on codeproject for around 11 years but I forgot the password to my first account and created this one to replace it.
RomTibi wrote:
I worked a little around the example I found but I wasn`t able to port in VC++6. If you can give me some advice I would be gratefull...
Almost everything can be ported to VC6 with the exception of some of the modern C++ templated code and C++11. What version of the Platform SDK are you using with VC6?
My problem simplified so I posted this http://www.codeproject.com/Messages/4192965/Need-help-to-port-example-in-VS6.aspx[^] because remained still a problem to me. I hope you don`t mind. :)
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
My problem simplified so I posted this http://www.codeproject.com/Messages/4192965/Need-help-to-port-example-in-VS6.aspx[^] because remained still a problem to me. I hope you don`t mind. :)
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
Hi RomTibi, No I don't mind at all. But I don't think anyone will be able to answer your question because to convert that project to VC6 takes alot of work and patience. You will just need to copy alot of Setup API structs and defines into a new header. If I have some free time this weekend I'll investigate it. Best Wishes, -David Delaune
-
Hi RomTibi, No I don't mind at all. But I don't think anyone will be able to answer your question because to convert that project to VC6 takes alot of work and patience. You will just need to copy alot of Setup API structs and defines into a new header. If I have some free time this weekend I'll investigate it. Best Wishes, -David Delaune
-
THX!:rose::thumbsup:
36. When you surround an army, leave an outlet free. ... Do not press a desperate foe too hard. SUN-TZU - Art of War
-
Hi, Just wanted to drop in and let you know that I have not forgotten about your issue. Unfortunately I was out of town last weekend and did not write any code. I still have it on my TODO list so let me know if you have solved your problem.