Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DTS to run activex srcipt vbs is failing 1

Status
Not open for further replies.

k8277

Programmer
Jan 10, 2003
104
US
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:

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
 
Have you tried it with just

Code:
Set WshNetwork = CreateObject("WScript.Network")

I don't believe VBScript recoginzes or requires the WScript. prefix.
 
Thanks gradley, that worked. I could have sworn I tried that earlier, but oh well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top