Scheduled Tasks and VBS Scripts

April 27, 2009 at 06:30:35
Specs: Windows XP
I finally got my VBS scripts setup to work the way I wanted, and then I set them to run as scheduled tasks. I'm having an issue every now and then with the first script failing. I already checked and the PC doesn't go into any type of power management/sleep/hibernate state.

Also, occasionally if the script seems to fail to save the file in the right location, I can find it somewhere along the path in the windows explorer. I'm using mostly send keys to get the path in the save location. I figure increasing the sleep timer in vbs during this part will help.

I mainly want to see if there's something I can do to get the first script to not fail in the scheduled task thing.

I did set another task to run about 10 minutes before these were scheduled. It seemed to help, but I had a failure over the weekend.


See More: Scheduled Tasks and VBS Scripts

Report •


#1
April 29, 2009 at 20:47:53
I'm having an issue every now and then with the first script failing.
Without seeing the script and without an error message, we can't help.

I'm using mostly send keys to get the path in the save location. I figure increasing the sleep timer in vbs during this part will help.
Presumably. VBScript has very little feedback from the GUI, so I suggest attempting to avoid SendKeys, or set the delay to something huge.


Report •

#2
April 30, 2009 at 06:22:28
Today the Script for Charlotte failed to complete what it was supposed to do, but yet Scheduled Task logs show it did.

"Charlotte.job" (025_Charlotte script for ROP.vbs)
Started 4/30/2009 5:04:01 AM
"Charlotte.job" (025_Charlotte script for ROP.vbs)
Finished 4/30/2009 5:06:31 AM
Result: The task completed with an exit code of (0).

Here is the script code. I don't think the script code is the problem. It seems like the script isn't running.


'Create the shell object
set oShell = CreateObject("WScript.Shell")
'Start up NetTerm
oShell.run"NetTerm.exe"
WScript.Sleep 1000
'Open phone directory to find site to telnet to
oShell.SendKeys("%")
WScript.Sleep 200
oShell.SendKeys"f"
WScript.Sleep 200
oShell.SendKeys"p"
WScript.Sleep 200
oShell.SendKeys"a"
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 3000

oShell.SendKeys"USER ID"
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 300
oShell.SendKeys"Password"
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 3000

'Start session logging to save the 24 hour log
oShell.SendKeys("%")+"f"
WScript.Sleep 200
oShell.SendKeys"l"
WScript.Sleep 200


'********************
'this part inputs the file name for the ROP log
'using yesterday's date
w= year(date-1)
p= right("0" & day(date()-1),2) 'Gives two-digit day of month.
m= right("0" & month(date()-1),2) 'Gives two-digit month.
y= right("" & year(date()-1),2) 'Gives two-digit year.
'Make sure the proper DRM number is used
oShell.SendKeys "025_" & y &"_" & m &"_" & p &".txt"
'********************

'find destination for the file to be saved.
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Down}")
WScript.Sleep 200
oShell.SendKeys"p"
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 1000
oShell.SendKeys"loc"
WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"rop"
WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys"rop"
WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys w
WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 1000
oShell.SendKeys m
WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 1000


'*****************
'The following line needs to change to match which site you are logging
oShell.SendKeys"025"
'*****************

WScript.Sleep 1000
oShell.SendKeys("{Enter}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 200

'***********************
'The following line will change daily
d=year(date)*10000+month(date)*100+day(date)
y=year(date-1)*10000+month(date-1)*100+day(date-1)
oShell.SendKeys "dslogread -s "
oShell.SendKeys y &"060000 -e "
oShell.SendKeys d &"060000 -N 10"
'***********************

'Wait for the log to finish before proceeding to the next.
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 120000
oShell.SendKeys"exit"
WScript.Sleep 200
oShell.SendKeys("{Enter}")
WScript.Sleep 5000
oShell.SendKeys("{Tab}")
WScript.Sleep 200
oShell.SendKeys("{Enter}")


I don't know why to accomplish this with out using the send keys to emulate manually doing this. Are there better ways to have the script open a program and navigate thru the telnet directory, login, start session logging with a changing file name based on the date?


Report •

Related Solutions


Ask Question