Sign in to follow this  
Followers 0
Aaron011312

Alternative way to recognize usb device, designate path?

7 posts in this topic

Did some searching of the forums here and I'm pretty sure the answer is already there in some form, but what I've found so far has been a little too technical for me to extract the right information from it.

I've made a little autoit script for a friend who connects a usb voice recorder to his win7 pc--in order to easily transfer the files to a particular place and name them, etc.

It worked well for a while, but I've got some FileMove statements that include a path with a drive letter.

I manually assigned the letter "V" to the device so that when he plugs it in, it won't matter what other USB items are connected or not (since Win will assign letters in a way I cannot predict).

This works sometimes.

The problem is that Win7 seems to occasionally fail to recognize the device--or something--and doesn't assign it to "V." So the script fails due to not finding the device to move files from it.

So what I need is some other method of specifying the copy/move paths... and the script has to know what device to communicate with also, since other usb drives and drive-letter devices are sometimes hooked up at the same time (and sometimes not).

I'm not clear on how to do that.

Share this post


Link to post
Share on other sites



Is there any way to put a check file on the device something like an empty text file called "hereIam.txt" and then search all attached drives for that file? Once it finds the file it can get the drive name. If you can't put a file on the drive like that, is there a file or folder you can search for that will only be on that drive?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, Aaron011312, welcome to the forum. I have run into something similar when attempting to connect to a Plug and Play device that hasn't been properly detected, with the script erroring out if it doesn't see the removable media. Someone may have a more native solution, but I simply install Microsoft's devcon into those scripts, then check for the drive and, if not found, run the -rescan option. Something like this:

$sDrive = DriveMapGet("T:")
If $sDrive = "" Then
  FileInstall("C:Devcon.exe", @TempDir & "Devcon.exe", 1)
  ShellExecute(@TempDir & "devcon.exe", "-rescan")
EndIf

Devcon is very small, about 77k. http://support.microsoft.com/kb/311272

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks.

BrewManNH: The hereiam.txt file idea might work. The device came from factory with a couple files on it in diff. formats and seems to a plain old FAT drive as far as Windows indicates. So... sould be possible to put a text file on it. What would be the command to get the drivename? And if I have the name, is there a way to use it in a path w/o the letter or retrieve the letter using the name? (I'm assuming "drivename" here is the volume label, am I right?)

(Edit: looks like DriveGetLabel would do the opposite of what I want: uses path to get label where I'd want to use label to get path. ... Also, looks like DriveGetDrive would allow me to fetch the drive letters of all removeables, so I could at least see if the assigned letter appears and if not generate a msg to say "unplug and replug and try again" or the like.)

JLogan3o13: the devcon idea might work, too. The system always detects the device; it just doesn't seem to "remember" what drive letter to give it. Still, a rescan might clear that up. Is devcon.exe a download from Microsoft or what? I'm not familiar with it.

Unfortunately (in a way) the failed drive letter assignment never happens on my PC and my access to the problem PC is somewhat limited so... I'll need to put some ideas together and take them to the site to test. I can simulate to an extent, though, by assigning the "wrong" letter to the device on my own PC, then running the script.

Edited by Aaron011312

Share this post


Link to post
Share on other sites

Found some functions that may help me also... some application of _pathmake and/or _pathsplit

In theory, could work:

- look for iamhere.txt

- if find, pathmake and set a variable

- have the filemove stuff use the variable for the path

Share this post


Link to post
Share on other sites

You could use DriveGetDrive with type "Removable" to get an array of drive letters for removable drives and then do a check with FileExists, using the drive letter and the file name you're looking for.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

==Probably solved==

Thanks for the help. I haven't had a good opportunity to test yet, but have verified that I can put a text file on the device (perhaps better, I can put a folder on it). So it should be possible to check each connected removable drive for the file/folder then run the script from there.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0