Removable Drive Letter Mapping

J

John Gregory

Removable Drive Letter Mapping

Is there a way to force the drive letter assignment for removable USB
drives? (in the same manner as mapping network drives perhaps?)

I frequently use two removable drives, a USB thumb drive with transfer
files, and a USB hard drive for back-up purposes. I use batch files to
transfer frequently used work files, and another program do perform backups,
however they are dependent upon drive letter assignments to work properly.
 
P

Pegasus \(MVP\)

John Gregory said:
Removable Drive Letter Mapping

Is there a way to force the drive letter assignment for removable USB
drives? (in the same manner as mapping network drives perhaps?)

I frequently use two removable drives, a USB thumb drive with transfer
files, and a USB hard drive for back-up purposes. I use batch files to
transfer frequently used work files, and another program do perform
backups,
however they are dependent upon drive letter assignments to work properly.

Have a look at USBDLM: http://www.uwe-sieber.de/usbdlm_e.html
 
J

John Gregory

I looked at the posted URL, the program discussed does not completely solve
my problem. It still seems to map the drives in the order they are installed.

What I would like, is something to put on a particular USB drive, in an
autorun file, that would map that drive to a specific letter regardless of
what computer it is installed into, or what order it is installed. Something
like the "net use" network mapping command.

Does something like this already exist?
 
P

Pegasus \(MVP\)

You could try the script below. Here is what you should do:
1. Copy & paste the code into c:\Windows\USBDrive.vbs.
2. Line 7 sets a polling interval of 10 seconds. Set it to 5
for your tests, then return it to 10.
2. Modify Line 8 to reflect the number of flash disks you wish to monitor.
3. Modify Line 11 to reflect your first USB disk.
4. Modify / insert extra lines for your remaining disks.
5. Each line starts with a line number. Unwrap those lines
that don't, then remove the line numbers.
6. Start a Command Prompt (Start / Run / cmd {OK}
7. Type this command: cscript c:\windows\USBDrive.vbs{Enter}
8. Connect one of your USB drives and watch what happens. Make
sure to wait 5 seconds before removing/inserting a flash disk.
9. Press Ctrl+Break to terminate the program.

To start the program automatically, use the Task Scheduler
to launch it at boot time.

1. '----------------------------------------------------
2. 'USB Drive letter changer
3. 'Code based on an idea by the Microsoft Scripting Guy
4. 'Version 1.0
5. '3 March 2008 FNL
6. '----------------------------------------------------
7. Const Interval = 10 'Interval between polls
8. Const disks = 2
9. Dim USB()
10. ReDim USB(disks)
11. USB(0) = "G: LARGE USB" 'Must be in upper case!
12. USB(1) = "H: SMALL USB" 'Must be in upper case!
13. Const command = "mountvol.exe "
14.
15. Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
16. Set oFSO = CreateObject("Scripting.FileSystemObject")
17. Set objWshShell = WScript.CreateObject("WScript.Shell")
18.
19. Set colEvents = objWMIService.ExecNotificationQuery _
20. ("Select * From __InstanceOperationEvent Within " & Interval _
21. & " Where TargetInstance isa 'Win32_LogicalDisk'")
22.
23. Do While True
24. Set objEvent = colEvents.NextEvent
25. If objEvent.TargetInstance.DriveType = 2 Then
26. If objEvent.Path_.Class = "__InstanceCreationEvent" Then
27. ALetter = objEvent.TargetInstance.DeviceID
28. Set oVol = oFSO.GetDrive(ALetter)
29. Label = UCase(oVol.VolumeName)
30. WLetter = ""
31. For i = 0 To disks - 1
32. If instr(USB(i), Label) > 0 then WLetter = Left(USB(i), 2)
33. Next
34. If (Not WLetter = ALetter) And (Not WLetter = "") Then
35. Set objExec = objWshShell.Exec (command & ALetter & " /L")
36. Vol = objExec.StdOut.ReadLine
37. Set objExec = objWshShell.Exec (command & ALetter & " /D")
38. Set objExec = objWshShell.Exec (command & WLetter & " " & Vol)
39. WScript.Echo "Drive letter changed from " & ALetter & " to " &
WLetter
40. End If
41. End If
42. End If
43. Loop
 
J

John Gregory

The script worked fine on the first USB drive (a USB 2 Gb flash drive), but
it would not work on the second USB drive (a USB 160 Gb hard drive).

The drive names are: "TRAVELDRIVE" and "JJG_160_GB"

Any Ideas?
 
P

Pegasus \(MVP\)

I can't tell without being there . . . However, you can
do your own debugging, by adding some lines to the
code as follows:
23. Do While True
24. Set objEvent = colEvents.NextEvent
25. If objEvent.TargetInstance.DriveType = 2 Then
26. If objEvent.Path_.Class = "__InstanceCreationEvent" Then
27. ALetter = objEvent.TargetInstance.DeviceID
28. Set oVol = oFSO.GetDrive(ALetter)
29. Label = UCase(oVol.VolumeName)
29a. wscript.echo "Drive Letter=" & ALetter & "xxx"
29b. wscript.echo "Volume Label=" & Label & "xxx"

Now do this:
1. Kill cscript.exe via the Task Manager or with taskkill.exe.
2. Open a Command Prompt.
3. Launch the script manually: cscript c:\windows\USBDrive.vbs
4. Insert your 160 GByte flash drive and watch the screen.

Remember to wait for at least "Interval" seconds between
insertions and removals.
 
J

John Gregory

I modified the script, and followed your instructions. The flash drive is
remapped, with no further action. The USB hard drive is mapped normally, and
does not appear to be affected by the script. The following is the output:

C:\>cscript c:\windows\USBDrive.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Drive Letter=E:xxx
Volume Label=TRAVELDRIVExxx
Drive letter changed from E: to X:
Drive Letter=X:xxx
Volume Label=TRAVELDRIVExxx

I connected the other USB drive here, but noting happend for a few minutes
and I ended the script

^C

I disconnected all removable drives and tried again.

C:\>cscript c:\windows\USBDrive.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

Drive Letter=X:xxx
Volume Label=TRAVELDRIVExxx
 
P

Pegasus \(MVP\)

I see what you mean. In spite of the original article referring to
"Removable Drive", the code used appears to pick up flash
disks only. I'll have to dig a little deeper . . .
 
P

Pegasus \(MVP\)

Problem solved. Line 25 used to look like so:
25. If objEvent.TargetInstance.DriveType = 2 Then

Replace it with these two lines:
25. DType = objEvent.TargetInstance.DriveType
25a. If (DType = 2) Or (DType = 3) Then

Please let me know how you go.
 
J

John Gregory

This works perfectly! Thank you for your help.

Pegasus (MVP) said:
Problem solved. Line 25 used to look like so:
25. If objEvent.TargetInstance.DriveType = 2 Then

Replace it with these two lines:
25. DType = objEvent.TargetInstance.DriveType
25a. If (DType = 2) Or (DType = 3) Then

Please let me know how you go.
 
U

Uwe Sieber

John said:
I looked at the posted URL, the program discussed does not completely solve
my problem. It still seems to map the drives in the order they are installed.

Then it's not correctely installed or the USBDLM.INI
isn't correct.
What I would like, is something to put on a particular USB drive, in an
autorun file, that would map that drive to a specific letter regardless of
what computer it is installed into, or what order it is installed. Something
like the "net use" network mapping command.

You could create an additional drive letter using
the SUBST command.

subst U: .

This must be started from the drive in question, so
the . stands for the current folder which is the root
of the drive by default.

Adavantage: As with USBDLM it's not required to give the
user admin previleges.

Disadvantage: The additional drive letter should be deleted
when the drive is removed.

subst U: /D


Uwe
 
R

Raas

Why does everyone (including MVPs) try to make things so complicated?

The following has worked without a single hitch since XP and continues to
work in Vista:

Insert your two USB drives > Click Start > Right Click Computers > Click on
Manage (wait) > Click on Disk Mangement (wait)> Right click the USB drive you
want to manage > Click Change Drive Letter and Paths > Select Change, then
assign the drive letter you want > Click OK and the USB drive letter is
changed and assigned, not only for this computer, but for any computer you
plug it into.

To change back again, just follow the above steps. It's provided for and
built into Windows XP and Vista.

Enjoy!

____________________
 
P

Pegasus \(MVP\)

Raas said:
Why does everyone (including MVPs) try to make things so complicated?
.. . . because the OP's question implied that he wanted
a fixed drive letter without manual intervention. While
your method is the standard and well-known way of
setting drive letters, it is not automatic.
 
J

John John

Raas said:
... the USB drive letter is
changed and assigned, not only for this computer, but for any computer you
plug it into.

And what if the computer you plug it into has already assigned the drive
letter to another device, are you suggesting that the Mount Manager will
favour a newly plugged in drive and assign it a letter already assigned
to another device?

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top