AutoIt Forums: USB Flash drives conflicting with network drives - AutoIt Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

USB Flash drives conflicting with network drives one workaround.... Rate Topic: -----

#1 User is offline   CyberSlug 

  • Overwhelmed with work....
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 3,587
  • Joined: 03-December 03
  • Location:Kentucky, USA

Posted 18 February 2005 - 12:45 AM

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=1

When 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.TXT

[ code='text' ]    ( ExpandCollapse - 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...")


#2 User is offline   jpm 

  • a Real GUI/debug lover
  • Icon
  • Group: Developers(Dev)
  • Posts: 8,505
  • Joined: 03-December 03
  • Location:Hauts de Seine, France

Posted 18 February 2005 - 08:51 AM

CyberSlug, on Feb 18 2005, 12:45 AM, said:

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=1

When 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.TXT

[ code='text' ]    ( ExpandCollapse - 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...")



you could have use DriveGetDrive ("removable") and start with the letter above c: ;)

#3 User is offline   CyberSlug 

  • Overwhelmed with work....
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 3,587
  • Joined: 03-December 03
  • Location:Kentucky, USA

Posted 18 February 2005 - 02:24 PM

jpm, on Feb 18 2005, 02:51 AM, said:

you could have use DriveGetDrive ("removable") and start with the letter above c: ;)

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.

#4 User is offline   SlimShady 

  • AutoIt lover
  • PipPipPipPipPipPipPip
  • Group: Full Members
  • Posts: 2,383
  • Joined: 08-April 04
  • Location:The Netherlands

Posted 18 February 2005 - 02:31 PM

This sounds like a bug and should be reported to Microsoft.

#5 User is offline   CyberSlug 

  • Overwhelmed with work....
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 3,587
  • Joined: 03-December 03
  • Location:Kentucky, USA

Posted 18 February 2005 - 02:35 PM

SlimShady, on Feb 18 2005, 08:31 AM, said:

This sounds like a bug and should be reported to Microsoft.

Microsoft already knows about it
http://support.microsoft.com/default.aspx?...kb;en-us;297694
but they have not fixed the problem! :mad:

#6 User is offline   jpm 

  • a Real GUI/debug lover
  • Icon
  • Group: Developers(Dev)
  • Posts: 8,505
  • Joined: 03-December 03
  • Location:Hauts de Seine, France

Posted 18 February 2005 - 03:26 PM

CyberSlug, on Feb 18 2005, 02:24 PM, said:

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.

on my XP SP2 it works fine I get 2 devices the A: and D: :angry:

#7 User is offline   CyberSlug 

  • Overwhelmed with work....
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 3,587
  • Joined: 03-December 03
  • Location:Kentucky, USA

Posted 18 February 2005 - 04:37 PM

jpm, on Feb 18 2005, 09:26 AM, said:

on my XP SP2 it works fine I get 2 devices the A: and D: :angry:

Sometimes it works and sometimes it does not.

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users