CyberSlug Posted February 17, 2005 Share Posted February 17, 2005 Problems where removable usb drives conflict with networked drive letters? Here's a script that will try to resolve the conflict by assigning the drive to B:I was inspired by this thread: http://www.tek-tips.com/viewthread.cfm?qid=938880&page=1When you run the program, it attempts to resolve the first USB/Network conflict by assigning the USB drive to B: and opening it. Probably requires Win 2000/XP and Admin rights. I've done limited testing and code commenting.REQUIRED DISKPART AND DP1.TXTexpandcollapse popup; Script to workaround a Windows bug that causes USB drive letter assignments to conflict with network drives ; The file dp1.txt contains two lines: ; list volume ; exit ; DiskPart.exe can be downloaded from http://www.microsoft.com/windows2000/techinfo/reskit/tools/new/diskpart-o.asp ; DiskPart documentation http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/diskpart.mspx ; ; Philip Gump - 17 Feb 2005 - AutoIt 3.1.0 Script ; #NoTrayIcon If DriveStatus("B:") <> "INVALID" Then Run("explorer b:") Exit EndIf FileChangeDir(@TempDir) Dim $diskPart = "DiskPart.exe" Dim $dpScriptOne = "dpScriptOne.txt" Dim $dpScriptTwo = "dpScriptTwo.txt" Dim $infoOutput = "DiskPartInfo.txt" FileInstall("C:\DISKPART.EXE", $diskPart) FileInstall("C:\dp1.txt", $dpScriptOne) ; Otherwise, need to do magic If @OSType <> "WIN32_NT" Then MsgBox(4096,"Error", "This program does not run on " & @OSVersion) EndIf If IsAdmin() Then MsgBox(4096,"USB Drive maybe not ready yet...", "If device is plugged and Windows says it's ready, click OK.") Else MsgBox(4096,"Error", "You do not have access to change drive letters. Click OK to exit") Exit EndIf SplashTextOn("Please wait...", @CRLF & @CRLF & "Assigning the USB drive to letter B:") Dim $info = "" $run = RunWait(@Comspec & " /c " & $diskPart & " /s " & $dpScriptOne & " > " & $infoOutput, "", @SW_HIDE) $info = FileRead($infoOutput, FileGetSize($infoOutput)) SplashOff() $InfoWithHeaderRemoved = StringTrimLeft($info, StringInStr($info, "Volume 0")-1) $info = StringSplit($InfoWithHeaderRemoved, @CRLF) ;Sample element in the $info array looks like: ; "Volume 2 C HARD DRIVE NTFS Partition 73 GB Healthy System" For $i = 1 to $info[0] If StringStripWS($info[$i], 8) = "" Then ExitLoop ;quit when hit blank lines If StringInStr($info[$i], "Removeable") Then $letter = StringMid($info[$i],16,1) $volume = StringMid($info[$i],10,1) If DriveMapGet($letter) <> "" Or Not StringInStr($info[$i],"0 B") Then ; if drive letter is mapped to something else and Size is larger than 0 bytes, then $handle = FileOpen($dpScriptTwo, 2) If $handle <> -1 Then FileWrite($handle, "select volume " & $volume & @CRLF & "assign letter=B") FileClose($handle) EndIf RunWait($diskPart & " /s " & $dpScriptTwo, "", @SW_HIDE) Run("explorer b:") Exit EndIf EndIf Next MsgBox(4096,"Error", "USB drive not detected; no drive letter assignment made...") Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
jpm Posted February 18, 2005 Share Posted February 18, 2005 Problems where removable usb drives conflict with networked drive letters? Here's a script that will try to resolve the conflict by assigning the drive to B:I was inspired by this thread: http://www.tek-tips.com/viewthread.cfm?qid=938880&page=1When you run the program, it attempts to resolve the first USB/Network conflict by assigning the USB drive to B: and opening it. Probably requires Win 2000/XP and Admin rights. I've done limited testing and code commenting.REQUIRED DISKPART AND DP1.TXTexpandcollapse popup; Script to workaround a Windows bug that causes USB drive letter assignments to conflict with network drives ; The file dp1.txt contains two lines: ; list volume ; exit ; DiskPart.exe can be downloaded from http://www.microsoft.com/windows2000/techinfo/reskit/tools/new/diskpart-o.asp ; DiskPart documentation http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/diskpart.mspx ; ; Philip Gump - 17 Feb 2005 - AutoIt 3.1.0 Script ; #NoTrayIcon If DriveStatus("B:") <> "INVALID" Then Run("explorer b:") Exit EndIf FileChangeDir(@TempDir) Dim $diskPart = "DiskPart.exe" Dim $dpScriptOne = "dpScriptOne.txt" Dim $dpScriptTwo = "dpScriptTwo.txt" Dim $infoOutput = "DiskPartInfo.txt" FileInstall("C:\DISKPART.EXE", $diskPart) FileInstall("C:\dp1.txt", $dpScriptOne) ; Otherwise, need to do magic If @OSType <> "WIN32_NT" Then MsgBox(4096,"Error", "This program does not run on " & @OSVersion) EndIf If IsAdmin() Then MsgBox(4096,"USB Drive maybe not ready yet...", "If device is plugged and Windows says it's ready, click OK.") Else MsgBox(4096,"Error", "You do not have access to change drive letters. Click OK to exit") Exit EndIf SplashTextOn("Please wait...", @CRLF & @CRLF & "Assigning the USB drive to letter B:") Dim $info = "" $run = RunWait(@Comspec & " /c " & $diskPart & " /s " & $dpScriptOne & " > " & $infoOutput, "", @SW_HIDE) $info = FileRead($infoOutput, FileGetSize($infoOutput)) SplashOff() $InfoWithHeaderRemoved = StringTrimLeft($info, StringInStr($info, "Volume 0")-1) $info = StringSplit($InfoWithHeaderRemoved, @CRLF) ;Sample element in the $info array looks like: ; "Volume 2 C HARD DRIVE NTFS Partition 73 GB Healthy System" For $i = 1 to $info[0] If StringStripWS($info[$i], 8) = "" Then ExitLoop;quit when hit blank lines If StringInStr($info[$i], "Removeable") Then $letter = StringMid($info[$i],16,1) $volume = StringMid($info[$i],10,1) If DriveMapGet($letter) <> "" Or Not StringInStr($info[$i],"0 B") Then ; if drive letter is mapped to something else and Size is larger than 0 bytes, then $handle = FileOpen($dpScriptTwo, 2) If $handle <> -1 Then FileWrite($handle, "select volume " & $volume & @CRLF & "assign letter=B") FileClose($handle) EndIf RunWait($diskPart & " /s " & $dpScriptTwo, "", @SW_HIDE) Run("explorer b:") Exit EndIf EndIf Next MsgBox(4096,"Error", "USB drive not detected; no drive letter assignment made...")<{POST_SNAPBACK}>you could have use DriveGetDrive ("removable") and start with the letter above c: Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2005 Author Share Posted February 18, 2005 you could have use DriveGetDrive ("removable") and start with the letter above c: <{POST_SNAPBACK}>Doesn't work... that's the whole point For example, you could insert a USB drive, and it does not appear in Windows Explorer because Windows tries to assign the drive to E: when E: is already mapped to a network drive.DriveGetType("E:") returns Network. The only way to can "see" the removable drive is by running diskmgmt.msc (or DiskPart.exe) and notice the drive letter conflict. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
SlimShady Posted February 18, 2005 Share Posted February 18, 2005 This sounds like a bug and should be reported to Microsoft. Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2005 Author Share Posted February 18, 2005 This sounds like a bug and should be reported to Microsoft.<{POST_SNAPBACK}>Microsoft already knows about ithttp://support.microsoft.com/default.aspx?...kb;en-us;297694but they have not fixed the problem! Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
jpm Posted February 18, 2005 Share Posted February 18, 2005 Doesn't work... that's the whole point For example, you could insert a USB drive, and it does not appear in Windows Explorer because Windows tries to assign the drive to E: when E: is already mapped to a network drive.DriveGetType("E:") returns Network. The only way to can "see" the removable drive is by running diskmgmt.msc (or DiskPart.exe) and notice the drive letter conflict.<{POST_SNAPBACK}>on my XP SP2 it works fine I get 2 devices the A: and D: Link to comment Share on other sites More sharing options...
CyberSlug Posted February 18, 2005 Author Share Posted February 18, 2005 on my XP SP2 it works fine I get 2 devices the A: and D: <{POST_SNAPBACK}>Sometimes it works and sometimes it does not. Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! 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