WSH to map multiple network drives

  • ljCharlie
  • Proficient
  • Proficient
  • ljCharlie
  • Posts: 343

Post 3+ Months Ago

Can anyone tell me why the following script isn't working?

Code: [ Select ]
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set AllDrives = WshNetwork.EnumNetworkDrives()

Drive_H = "H:" 'History drive
RemotePath_H = "\\lst2\History"
Drive_I = "I:" 'History drive
RemotePath_I = "\\lst2\Information"
Drive_O = "O:" 'History drive
RemotePath_O = "\\lst2\OnlineManual"
Drive_S = "S:" 'History drive
RemotePath_S = "\\lst2\data$"
Drive_T = "T:" 'History drive
RemotePath_T = "\\lst2\Templates$"

AlreadyConnected = False
For i = 0 To AllDrives.Count - 1 Step 2
If AllDrives.Item(i) = Drive_H Then AlreadyConnected = True
Next
For i = 0 To AllDrives.Count - 1 Step 2
If If AllDrives.Item(i) = Drive_I Then AlreadyConnected = True
Next
For i = 0 To AllDrives.Count - 1 Step 2
If If AllDrives.Item(i) = Drive_O Then AlreadyConnected = True
Next
For i = 0 To AllDrives.Count - 1 Step 2
If If AllDrives.Item(i) = Drive_S Then AlreadyConnected = True
Next
For i = 0 To AllDrives.Count - 1 Step 2
If If AllDrives.Item(i) = Drive_T Then AlreadyConnected = True
Next

If AlreadyConnected = False then
WShNetwork.MapNetworkDrive Drive_H, RemotePath_H
WShNetwork.MapNetworkDrive Drive_I, RemotePath_I
WShNetwork.MapNetworkDrive Drive_O, RemotePath_O
WShNetwork.MapNetworkDrive Drive_S, RemotePath_S
WShNetwork.MapNetworkDrive Drive_T, RemotePath_T
'WshShell.PopUp "Drive " & DriveLetter & " connected successfully."

Else
WShNetwork.RemoveNetworkDrive Drive_H
WShNetwork.RemoveNetworkDrive Drive_I
WShNetwork.RemoveNetworkDrive Drive_O
WShNetwork.RemoveNetworkDrive Drive_S
WShNetwork.RemoveNetworkDrive Drive_T
'WshShell.PopUp "Drive " & DriveLetter & " disconnected."
End if
  1. Set WshShell = WScript.CreateObject("WScript.Shell")
  2. Set WshNetwork = WScript.CreateObject("WScript.Network")
  3. Set AllDrives = WshNetwork.EnumNetworkDrives()
  4. Drive_H = "H:" 'History drive
  5. RemotePath_H = "\\lst2\History"
  6. Drive_I = "I:" 'History drive
  7. RemotePath_I = "\\lst2\Information"
  8. Drive_O = "O:" 'History drive
  9. RemotePath_O = "\\lst2\OnlineManual"
  10. Drive_S = "S:" 'History drive
  11. RemotePath_S = "\\lst2\data$"
  12. Drive_T = "T:" 'History drive
  13. RemotePath_T = "\\lst2\Templates$"
  14. AlreadyConnected = False
  15. For i = 0 To AllDrives.Count - 1 Step 2
  16. If AllDrives.Item(i) = Drive_H Then AlreadyConnected = True
  17. Next
  18. For i = 0 To AllDrives.Count - 1 Step 2
  19. If If AllDrives.Item(i) = Drive_I Then AlreadyConnected = True
  20. Next
  21. For i = 0 To AllDrives.Count - 1 Step 2
  22. If If AllDrives.Item(i) = Drive_O Then AlreadyConnected = True
  23. Next
  24. For i = 0 To AllDrives.Count - 1 Step 2
  25. If If AllDrives.Item(i) = Drive_S Then AlreadyConnected = True
  26. Next
  27. For i = 0 To AllDrives.Count - 1 Step 2
  28. If If AllDrives.Item(i) = Drive_T Then AlreadyConnected = True
  29. Next
  30. If AlreadyConnected = False then
  31. WShNetwork.MapNetworkDrive Drive_H, RemotePath_H
  32. WShNetwork.MapNetworkDrive Drive_I, RemotePath_I
  33. WShNetwork.MapNetworkDrive Drive_O, RemotePath_O
  34. WShNetwork.MapNetworkDrive Drive_S, RemotePath_S
  35. WShNetwork.MapNetworkDrive Drive_T, RemotePath_T
  36. 'WshShell.PopUp "Drive " & DriveLetter & " connected successfully."
  37. Else
  38. WShNetwork.RemoveNetworkDrive Drive_H
  39. WShNetwork.RemoveNetworkDrive Drive_I
  40. WShNetwork.RemoveNetworkDrive Drive_O
  41. WShNetwork.RemoveNetworkDrive Drive_S
  42. WShNetwork.RemoveNetworkDrive Drive_T
  43. 'WshShell.PopUp "Drive " & DriveLetter & " disconnected."
  44. End if


Many thanks for your help in advance!

ljCharlie
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ljCharlie
  • Proficient
  • Proficient
  • ljCharlie
  • Posts: 343

Post 3+ Months Ago

Okay, I got it working now.

ljCharlie
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

what type of coding is that? and what it for?
  • ljCharlie
  • Proficient
  • Proficient
  • ljCharlie
  • Posts: 343

Post 3+ Months Ago

It is WSH. I am trying to map multiple network drives. I have two "IF" and I don't need that man "For" loops that's why it didn't work.

ljCharlie

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 124 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.