Member Avatar for RudyM

Hi all,

I am trying to schedule a Task that will run a vb script to open a browser, send some keys, and finally close the browser. The task starts, but seems to hang. The task is created as follows:

schtasks.exe /Create /RU "SYSTEM" /SC "DAILY" /MO "1" /ST "23:00" /TN "Open Browser" /TR "C:\somefolder\somescript.vbs"

The script looks like:

Set oShell = WScript.CreateObject("WScript.Shell")

oShell.Exec "iexplore http://localhost/mylocalsite"

WScript.Sleep 10000

oShell.SendKeys "uname"
oShell.SendKeys "{TAB}upassword"
oShell.SendKeys "{ENTER}"

WScript.Sleep 20000

'Close browser'
oShell.SendKeys "^w"

Also, adding c:\program files\internet explorer\ to my path variable allows me to execute iexplore as a command.

Just a thought. Since IE is not usually used for non-interactive tasks, SYSTEM may be the wrong user context.
Also, the new security noted at https://www.autoitscript.com/autoit3/docs/libfunctions/_IECreate.htm can cause the browser to ask a question and you are not there to answer.

PS. This is mainly a guess here. I'm not there to see and duplicate this setup. But I'll share the above and hope.

Member Avatar for RudyM

@rproffitt, thanks for the link, but I'm not sure how I could use it in the VBScript. As for the use of "SYSTEM" in a user context, I've also tried using local accounts and have not succeeded.

Also, the script runs without issue when executed manually.

Think context. Use your account instead of system. I'm sure this has been kicked around many times, since IE is in some non-gui instance, you may find sending keystrokes to fail.

Maybe your goal is to log into a site daily or something. Maybe there are other ways like telnet and other scripts.

Member Avatar for RudyM

This is related to another problem that seems to solve itself when I log in and view a web-page and finally just close it. I will look into other alternatives, thanks.

Member Avatar for RudyM

I retried this in a batch file and it worked.

thanks for sharing this ,
I had same problum but now it solved !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.