sph0x Posted October 26, 2007 Posted October 26, 2007 hello there!i'm not very good in using autoit, so i hope to get some help here: all i need is a function to get the driveletter from an usb-drive.i want to start and stop some programms on a usb-device via autoit - and i want to do this on many different computers, so the drive-letter to the applications is changing all the time. even on one single machine the driveletter is not constant, sometimes i have to change it manually (xp-thingy), sometimes the network-admin is messing around and network devices change their letter.... whatsoever, i don't want to do a simple search for the .exe-files, this would take too much time. so i thought about searching a pattern like "*\myknownfolder\", because the "myknownfolder" (of course) exists on the usb-device, and by locating it i thought i could get the matching driveletter from the search result.this does not sound very difficult, but i cant get this thing working.here is what i tried so far:$var = DriveGetDrive( "all" ) If NOT @error Then For $i = 1 to $var[0] $search = FileFindFirstFile ( $var[i] & "\myknownfolder") If Not $search = -1 Then $usb = $var[i] EndIf FileClose($search) Next MsgBox(4096, "Found Driveletter:", $usb) EndIfdoes anyone know how to get this working? or, if i'm completely wrong here - does anyone know how to manage a function like this?thank you for reading - and for all helpfull answers,nice weekend,sph
Nahuel Posted October 26, 2007 Posted October 26, 2007 (edited) Does this work better?$var = DriveGetDrive( "all" ) $usb="Not found" If NOT @error Then For $i = 1 to $var[0] $search = FileExists( $var[$i] & "\Scripts") If $search Then $usb = $var[$i] ExitLoop EndIf Next MsgBox(4096,"", "Found Driveletter: "& StringUpper($usb)) EndIfYou could also try: DriveGetDrive ( "REMOVABLE" ) for USB disks. Edited October 26, 2007 by Nahuel
sph0x Posted October 26, 2007 Author Posted October 26, 2007 YES, a whole lot better - thank you very much! You could also try: DriveGetDrive ( "REMOVABLE" ) for USB disks.yes, but some of my usb-stuff is mounted via truecrypt, and so it's not recognized as a removable drive, that's why i guess "all" would work better.so, your script works, it shows me the driveletter as wanted - but there is another thing: i get an annoying error-message, i think it comes when the script tries to search the a:\ directory, when no floppy disc is inserted. is there a way to exclude the a:-drive?thanks alot,bye!
Nahuel Posted October 26, 2007 Posted October 26, 2007 Yes, I had the same problem. Try this: $var = DriveGetDrive( "all" ) $usb="Not found" If NOT @error Then For $i = 1 to $var[0] If $var[$i]<>"a:" Then $search = FileExists( $var[$i] & "\Scripts") If $search Then $usb = $var[$i] ExitLoop EndIf EndIf Next MsgBox(4096,"", "Found Driveletter: "& StringUpper($usb)) EndIf
sph0x Posted October 26, 2007 Author Posted October 26, 2007 just GREAT! thank you very much - this is exactly what i need to continue with some simple commands, and now it will work whatever the usb-device is called. thank you very much! nice weekend, bye!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now