I have the following vbs file that runs fine if I run it from windows explorer. If I try to create a task in a DTS and run the same code I get the error: Variable is undefined: WScript. It errors on the line:
Set WshNetwork = WScript.CreateObject("WScript.Network")
The code is mapping a network drive:
Set WshNetwork = WScript.CreateObject("WScript.Network")
The code is mapping a network drive:
Code:
Option Explicit
Dim WshNetwork, oDrives, i
'-- Setting objects --
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set oDrives = WshNetwork.EnumNetworkDrives
DriveMapper "z:", "\\server\share"
Sub DriveMapper(Drive, Share)
For i = 0 to oDrives.Count -1 Step 2
if LCase(Drive) = LCase(oDrives.Item(i)) then
if not LCase(Share) = LCase(oDrives.Item(i+1)) then
WshNetwork.RemoveNetworkDrive Drive, true, true
Else
Exit Sub
End if
End if
Next
WshNetwork.MapNetworkDrive Drive, Share,,"user", "password"
Set WshNetwork = nothing
Set oDrives = nothing
End Sub