Re: Removable Drive Letter Mapping

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.


"John Gregory" <JohnGregory@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:020084E1-498F-4FD9-9245-2AABDEA0B112@xxxxxxxxxxxxxxxx
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?

"Pegasus (MVP)" wrote:

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


"John Gregory" <JohnGregory@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8B0CC6EC-ED68-487C-8E37-B43A33DB2EC6@xxxxxxxxxxxxxxxx
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?






.



Relevant Pages

  • Re: Removable Drive Letter Mapping
    ... You could try the script below. ... Modify Line 8 to reflect the number of flash disks you wish to monitor. ... Connect one of your USB drives and watch what happens. ...
    (microsoft.public.windowsxp.general)
  • Re: Removable Drive Letter Mapping
    ... Modify Line 8 to reflect the number of flash disks you wish to monitor. ... Modify Line 11 to reflect your first USB disk. ... Connect one of your USB drives and watch what happens. ...
    (microsoft.public.windowsxp.general)
  • Re: Help with a Mac Plus
    ... >> write such disks of course). ... > This trick will only work on the Apple floppy drives. ... I *think* that's only because the new USB drives don't work ... The sellotape trick above worked in the old days on various computers: ...
    (comp.sys.mac.system)
  • How to change the SendTo menu ??
    ... I have 17 different disks (intern harddrives as well as usb drives) in my ... Asger ...
    (microsoft.public.windowsxp.configuration_manage)
  • Two CurrentControlSet (s)
    ... I want to modify the IRPStackSize value in the registry to enable me ... to share USB drives. ...
    (microsoft.public.windowsxp.help_and_support)