Re: [WIN] GetLogicalDrives returns drives NOT present
- Posted by CChris <christian.cuvier at agricultu?e.?ouv.fr> Jan 29, 2008
- 1125 views
Dan Moyer wrote: > > CChris wrote: > > > > Dan Moyer wrote: > > > > > > Bernie Ryan wrote: > > > > > > > > Dan Moyer wrote: > > > > > > > > > > > > > > > When I wrap the function GetLogicalDrives, it works, except that it > > > > > returns drive numbers for drives that aren't actually there yet, > > > > > exactly > as</font></i> > > > > > "My Computer" does, ie, usb drives that aren't currently plugged in. > > > > > And > then</font></i> > > > > > if I use "dir" to see if a drive is "ready", I get a non-fatal error > > > > > message. > > > > > > > > > > > > > > > What I was trying to do was find out what drives are on the system, > > > > > and then > > > > > if they were removable or not. But I don't want to check drives that > > > > > aren't > > > > > actually there. > > > > > > > > > > Any suggestions?? > > > > > > > > Dan: > > > > > > > > Be sure that you unmount the USB drives before you remove them. > > > > > > > > Windows when it loads assigns the drive numbers when it boots > > > > > > > > and when you remove a USB drive it's drive number does not go > > > > > > > > away. > > > > > > > > You did't say what operating system you are using which may make a > > > > > > > > difference. > > > > > > > > Here is a link that might help: > > > > > > > > <a > > > > href="http://www.uwe-sieber.de/usbstick_e.html">http://www.uwe-sieber.de/usbstick_e.html</a> > > > > > > > > Bernie > > > > > > Thanks for the observation & link Bernie. > > > > > > I'm using WinXP, and 4 different "removable drives" have shown up as > > > present, > > > as far as I remember, from first time I turned on the system, before ever > > > mounting > > > any usb flashdrives. Those are the drives that show up from > > > GetLogicalDrives. > > > Any time I mount a usb drive, I unmount it via the "safely remove > > > hardware" > > > icon in systray, which is currently showing those same 4 not actually > > > present > > > drives; when I do mount a usb flash drive, it shows up also, and then > > > dissappears > > > from the "safely remove hardware" list after I click there to unmount it. > > > > > > > > > So my problem *seems* (?) to be, how to discern if a drive that is > > > asserted > > > > > > by the system to be "there" is actually "ready" or not. I thought to use > > > "dir" to test that, but it brought up non-fatal errors which required user > > > clicks in a message box to continue, which is not desireable. > > > > > > Dan > > > > GetLogicalDrives doesn't seem the way to go. > > Instead, the code at the following address is supposed to list all available > > volumes with their paths, which looks like what you are after: > > <a > > href="http://msdn2.microsoft.com/en-us/library/bb891980">http://msdn2.microsoft.com/en-us/library/bb891980</a>(VS.85).aspx > > Of course, this is in C, but the code is clean and pretty straightforward to > > translate. > > > > CChris > > Chris: > I kinda thought *logical* drives might be at least part of the problem I'm > having, but I don't think I can decipher/translate the C code. I'm > wondering if there isn't some way to defeat the presentation of the error > messages? I thought there is something along those line in Win32Lib? > If what you get is a dialog box that allows you to continue executing (yes/no/cancel), then calling setWarning(0) before running your code will suppress it. I must say that it is not the recommended way... I'll try to find some time to post a translation of the code at MSDN. Actually, it's pretty simple: get all known volume strings, then retrieve all the paths for each of those strings. Because there are sequences of chars everywhere, the code isn't as short as you might exect at first, but... it may be worth to try again. </snip> CChris