[WD15] How to get the drive letter of a USB memory stick?

Startbeitrag von Ola am 27.01.2011 10:47

The question is in the header:
How to get the drive letters of USB memory sticks currently attached to the computer, in WD15, in Windows 7 64b.

best regards
Ola
http://www.pienoismalli.com

Antworten:


Hi Ola, see: http://www.windev.at/html/usbfind.html


von Jimbo - am 27.01.2011 10:52
Hi Guenter,

Thanks for good info. I already know, how to find a USB-stick's serial number, thanks to you and the info on your page, but now I would also like know what drive letter is assigned to it.

So you are saying, that that the easiest way to find it is executing NirSoft's USBDeview from Windev and then checking through the result it return?

best regards
Ola

von Ola - am 27.01.2011 12:02
Ola,
you can search this registry key "HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices"
with the devices you get from USBListDevice()
Works on XP/Vista - not sure about W7

von Arie - am 27.01.2011 12:17
or you could call an wmi query from code?

von bosher - am 27.01.2011 12:29
Hi bosher,

First time I hear about wmi query:-)

Can you give an example in W-language?

best regards
Ola

von Ola - am 27.01.2011 13:34
Hi Arie,

Thanks. It seems to be there, so surely it can also be searched for. I'll check also some of my older macines to see how it is listed in their registries, as there seem to be differences between 64 and 32 bit handling.

best regards
Ola

von Ola - am 27.01.2011 13:38

Hi Ola, it's also about drive letters. USBFind(..) doesn't fully work in that respect - it recognizes USB memory sticks but NOT removable hard drives. The solution is to scan the drive letters and find the associated devices. Guenter



von Jimbo - am 27.01.2011 14:43
I have more or less the same problem, this is the code
i try to find a usbstick with a certain file on it (need it for input).
when i debug it i see that my file is found and i know my drive letter then (f)
my only problem is that I can't get the procedure to return the driveletter
so where do i go wrong

best regards

RdJ


PROC_ExploreUSB(sBeginning)
sList is string
sSerial is string
sDrive is string
DriveToReturn,TestFileName is string
sList = USBListDevice(sBeginning)
IF sList "" THEN
sDevice is string
FOR EACH STRING sDevice OF sList SEPARATED BY CR
IF Left(sDevice,12) = "USBSTOR\DISK" THEN
sSerial = ExtractString(ExtractString(sDevice,4,"&",FromBeginning),2,"\",FromBeginning)
FOR x = 65 TO 90
IF Position(USBFind(USBDrive,Charact(x)+":"),NoSpace(sSerial)) > 0 THEN
sDrive = Charact(x)+":"
TestFileName=sDrive+"\testfile.txt"
IF fFileExist(TestFileName) THEN
DriveToReturn=sDrive

END
END
END
END
PROC_ExploreUSB(sDevice)
END
END

RESULT DriveToReturn



von RdJ - am 27.01.2011 15:39
I was working with an almost similar problem today. Use a flag. Hoist the flag if the drive is found, and test for the flag before the procedure calls itself again: If the flag is up, don't call it again.

Best regards
Ola

P.S. The above instruction helps you get a result from the procedure, but not necessarily the correct drive letter...

von Ola - am 27.01.2011 22:11
Yeah,
Tried that before but didn't work
I saw the drive letter was found but didn't get it back in my end result.
After a night sleep I saw that I was forgotten that I have to get my result back also when I call itself again ;-)
Corrected that so It works now

In my case it is the correct drive letter because the file I am looking for is unique and has a code in it so I check that.

regards,

RdJ

von RdJ - am 28.01.2011 09:41
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.