I have a scheduled task that's running, but it doesn't seem to be working. This task executes a batch file. The batch file contains only one line:
wscript c:myfolder/myscript.vbs
This VBScript file starts a command prompt, executes vpncli
, sleeps for one minute, then proceeds to set up a connection sending the user name/password to the command line window.
This works OK when running the batch file from a command prompt window, but no success using the scheduled task. The account that it runs the task under is a service managed account. After running the task, I check in a separate command line window vpncli
, and see that the connection is still disconnected.
What must be taken into account on executing batch file in scheduled task to resolve this problem?
Below is part of the code I'm using to execute in a CMD shell. There is executed the following subroutine:
Sub VPN_open
? VPN_Profile = "vpn.myhost.com"
? VPN_User = "USERNAME"
? ' If the password contains special characters, enclose the characters in curly braces {}.
? VPN_Password = "PASSWORD"
?
? oShell.Run "cmd" ?
? WScript.Sleep 100
?
? oShell.AppActivate "C:WindowsSystem32cmd.exe" ?
? oShell.SendKeys "vpncli connect " & VPN_Profile & "~"
?
? WScript.Sleep 10000
?
? oShell.SendKeys VPN_User & "~"
?
? WScript.Sleep 5000
?
? oShell.SendKeys VPN_Password & "~"
?
? WScript.Sleep 10000
?
? oShell.SendKeys "exit~" ?
End Sub 'VPN_open
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…