mreinhart Posted January 24, 2008 Share Posted January 24, 2008 I am new to this site and have played a little with autoit. Has anyone come up with an autoit script to detect a usb drive AND force it to a specific drive letter. We have multiple computers in our organizaiton and users have created their own batch backup files. I have seen the scripts to find a specific file on a usb drive, which do work. But I am at a loss as how to force the drive letter to change. Link to comment Share on other sites More sharing options...
Greenhorn Posted January 24, 2008 Share Posted January 24, 2008 Moin,take a look at this Link, please ...http://www.uwe-sieber.de/usbdlm.htmlGreetzGreenhorn Link to comment Share on other sites More sharing options...
mreinhart Posted January 24, 2008 Author Share Posted January 24, 2008 Yes, I have tried the USBDLM. It did not work on all of the computers. Still looking for an autoit script to brute force a drive letter. Thanks for the suggestion though. Link to comment Share on other sites More sharing options...
Greenhorn Posted January 24, 2008 Share Posted January 24, 2008 For which OS ??? Only XP or also other Windows Versions ... Link to comment Share on other sites More sharing options...
mreinhart Posted January 24, 2008 Author Share Posted January 24, 2008 The OS is XP-Pro with a few XP-home. I've been playing with the "usbletter.exe" utility from Novell. It will at least give the user a chance to change the drive letter manually (and easily) If I add the command "usbletter x" it will default to x: as the first choice for a letter and the user just has to click OK. Unfortunately, if I run that utility a bunch of times (durring testing) it locks up and I have to go to Task Mgr to shut them down. Link to comment Share on other sites More sharing options...
Greenhorn Posted January 24, 2008 Share Posted January 24, 2008 Wait a minute, please. I'm trying to make a Script, but don't know, if it works ... Link to comment Share on other sites More sharing options...
Greenhorn Posted January 24, 2008 Share Posted January 24, 2008 I think there is a way, but be patient, my dear, I need a little time to debug ... Greetz Link to comment Share on other sites More sharing options...
Greenhorn Posted January 24, 2008 Share Posted January 24, 2008 (edited) O.K., here we go ... I didn't tested it, cause I don't want to curl my Drive Letters. But the Syntax is O.K. ... If you have a Testmaschine, give it a trial, but do it on your own risk !!! Description: Create a Textfile on the root Directory of your Pen Drive, name it 'USB_Pen.txt'. Put the following content into this file and save it: list volume exit Here comes the Script. It will create a second textfile 'diskpart.txt' on your Pen Drive ... You can customize the way yu want the Script to run, if you want. I left the Debug lines in there for testing ... Tomorrow I will append more Comment lines at the Script (too lazy and tired now ...) expandcollapse popup#include <Array.au3> $sDrvLetterNew = InputBox('Select new Drive Letter', 'Select Drive Letter to assign, please !') If @error = 1 Then Exit ; Cancel Button pushed. $arDrvList = DriveGetDrive('REMOVABLE') ; Get list of removable Drives. For $i = 1 To $arDrvList[0] If $arDrvList[$i] = 'a:' Then ContinueLoop ; except floppy Drive. If FileExists($arDrvList[$i] & '\USB_Pen.txt') Then $sDrvLetter = $arDrvList[$i] $sDrvLabel = DriveGetLabel($arDrvList[$i]) EndIf Next $PID = Run(@SystemDir & '\diskpart.exe /s "' & $sDrvLetter & '\USB_Pen.txt"', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $arLine = _StreamRead($PID) ; Read out Volume number of Pen Drive. ;_ArrayDisplay($arLine) For $i = 1 To $arLine[0] ;MsgBox(0, "", $arLine[$i]) If StringInStr($arLine[$i], $sDrvLabel) Then ;MsgBox(0, "", $arLine[$i]) $arDrvVolume = StringRegExp($arLine[$i], '(Volume \d\d?)', 1) EndIf Next ;_ArrayDisplay($sDrvVolume) If $arDrvVolume Then Dim $fhTextCommands = FileOpen($sDrvLetter & '\diskpart.txt', 2) $sTextCommands = 'select ' & $arDrvVolume[0] & @CRLF & 'assign letter ' & $sDrvLetterNew & @CRLF & 'exit' FileClose(FileWrite($fhTextCommands, $sTextCommands)) EndIf $iMsg = MsgBox(4145, "Let's get it on ...", 'Are you sure to continue ?') If $iMsg = 2 Then Exit Else Run(@SystemDir & '\diskpart.exe /s "' & $sDrvLetter & '\diskpart.txt"', '', @SW_HIDE) EndIf Exit Func _StreamRead($PID) While 1 $line = StdoutRead($PID) If @error Then ExitLoop ;MsgBox(0, "STDOUT read:", $line) $arLine = StringSplit($line, @LF) WEnd While 1 $line = StderrRead($PID) If @error Then ExitLoop EndIf MsgBox(0, "STDERR read:", $line) WEnd Return $arLine EndFunc ;==>_StreamRead I hope it works and it is the way you want, else I wastet my time ... Roger, over and out ! (No, I didn't ment you, Roger ! ) Greetz Greenhorn Edited January 25, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
AzKay Posted January 24, 2008 Share Posted January 24, 2008 (edited) Heres my version:$oForce = "W:" $oRemove = True If $oRemove = True Then RunWait(@ComSpec & " /c subst /d " & $oForce, "", @SW_HIDE) Else For $i = 65 To 90 If FileExists(Chr($i) & ":\usb") Then RunWait(@ComSpec & " /c subst " & $oForce & " " & Chr($i) & ":\", "", @SW_HIDE) Exit EndIf Next EndIfJust make a file called "usb" on the usb drive, And run the script.$oForce =, In your case "X:"$oRemove =, True to "remove" the "redirection", False to "install" it.EDIT::You "could" use DriveGetDrive, or DriveGetType.But I prefer my way x3And, I believe the "redirection" will delete itself on reboot too. Edited January 24, 2008 by AzKay # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Greenhorn Posted January 25, 2008 Share Posted January 25, 2008 Heres my version: $oForce = "W:" $oRemove = True If $oRemove = True Then RunWait(@ComSpec & " /c subst /d " & $oForce, "", @SW_HIDE) Else For $i = 65 To 90 If FileExists(Chr($i) & ":\usb") Then RunWait(@ComSpec & " /c subst " & $oForce & " " & Chr($i) & ":\", "", @SW_HIDE) Exit EndIf Next EndIf Just make a file called "usb" on the usb drive, And run the script. $oForce =, In your case "X:" $oRemove =, True to "remove" the "redirection", False to "install" it. EDIT:: You "could" use DriveGetDrive, or DriveGetType. But I prefer my way x3 And, I believe the "redirection" will delete itself on reboot too. You create just a virtual Drive with SUBST ! Link to comment Share on other sites More sharing options...
mreinhart Posted January 25, 2008 Author Share Posted January 25, 2008 Greenhorn, Thanks for the script. Although when I run it, I get an err in line 26--If $sDrvVolume Then-- about the $sDrvVolume not being defined. Link to comment Share on other sites More sharing options...
AzKay Posted January 25, 2008 Share Posted January 25, 2008 You create just a virtual Drive with SUBST !.. Point being?It gets the job done, Wheres the problem? # MY LOVE FOR YOU... IS LIKE A TRUCK- # Link to comment Share on other sites More sharing options...
Greenhorn Posted January 25, 2008 Share Posted January 25, 2008 (edited) Oh, sorry, my dear, I was too tired yesterday ... I changed the name of the variable from $s... to $ar..., cause it's an array which is returned from $arDrvVolume = StringRegExp($arLine[$i], '(Volume \d\d?)', 1) Just change '$sDrvVolume' to '$arDrvVolume' and it's righty right ! I'll correct the Script in my previous post, too ! Please let me know if it works properly for you !!! Greetz Edited January 25, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
mreinhart Posted January 25, 2008 Author Share Posted January 25, 2008 AzKay, I tried your script also. Yours is very sweet an simple (Sorry Greenhorn) I just need to add an error message in case it can not find the 'usb' file Thank you for all of your help Link to comment Share on other sites More sharing options...
Greenhorn Posted January 25, 2008 Share Posted January 25, 2008 (edited) .. Point being?It gets the job done, Wheres the problem?If it does, it's fine ! But I read also about problems by using it this way, cause you create just a virtual path to the 'real' path ...http://newyear2006.wordpress.com/2006/09/1...gen-aktiv-sind/@mreinhartplease test both Scripts, if it's ok for you !Greetz to both of you ! Edited January 25, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
mehrdad39 Posted July 7, 2009 Share Posted July 7, 2009 I am very new to scripting and programming (less than new!!!) I am interested in doing the same thing. Would you be able to provide a bit more instruction on how to get your script working? What kind of file to creat on the USB drive? where to run the script from (target system or developer system)? Thanks Mehrdad Heres my version: $oForce = "W:" $oRemove = True If $oRemove = True Then RunWait(@ComSpec & " /c subst /d " & $oForce, "", @SW_HIDE) Else For $i = 65 To 90 If FileExists(Chr($i) & ":\usb") Then RunWait(@ComSpec & " /c subst " & $oForce & " " & Chr($i) & ":\", "", @SW_HIDE) Exit EndIf Next EndIf Just make a file called "usb" on the usb drive, And run the script. $oForce =, In your case "X:" $oRemove =, True to "remove" the "redirection", False to "install" it. EDIT:: You "could" use DriveGetDrive, or DriveGetType. But I prefer my way x3 And, I believe the "redirection" will delete itself on reboot too. Link to comment Share on other sites More sharing options...
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