netdesignscs_sunnyvale
asked on
Scheduling a task with VB Script and Windows Task Scheduler.
Hi,
I need to have a scheduler execute a web page on my my machine with VBS Script and Windows Task Scheduler.
The referred link is
http://weblogs.asp.net/steveschofield/archive/2006/09/28/Schedule-a-task-to-call-a-webpage-using-Task-scheduler_2E00_.aspx
As per the link
My vb script is(script file name is HttpRequester.vbs)
-------------------------- ---------- ---------- ---------- ---------- -
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XM LHTTP")
URL = "http://localhost:59393/TaskScheduler.aspx"
objRequest.open "POST", URL , false
objRequest.Send
The TaskScheduler.aspx will have some database related operations.for the testing purpose i am having only a repose.write method in the load event of the aspx page.
Aspx.cs page is
---------------------
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FTMS
{
public partial class TaskScheduler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("TaskSchedu ler.aspx was called:" + System.DateTime.Now);
}
}
}
I need to display this message while executing the task scheduler.
I set up the windows task scheduler to run daily once.
But instead of showing the message written in the load event of the aspx page it is opening the vbscript file .
Can anybody please help me on how to schedule this task on windows task scheduler? and is it possible to use javascript file instead of vbscript for scheduling the task?
Thanks
Priya
I need to have a scheduler execute a web page on my my machine with VBS Script and Windows Task Scheduler.
The referred link is
http://weblogs.asp.net/steveschofield/archive/2006/09/28/Schedule-a-task-to-call-a-webpage-using-Task-scheduler_2E00_.aspx
As per the link
My vb script is(script file name is HttpRequester.vbs)
--------------------------
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XM
URL = "http://localhost:59393/TaskScheduler.aspx"
objRequest.open "POST", URL , false
objRequest.Send
The TaskScheduler.aspx will have some database related operations.for the testing purpose i am having only a repose.write method in the load event of the aspx page.
Aspx.cs page is
---------------------
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace FTMS
{
public partial class TaskScheduler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write("TaskSchedu
}
}
}
I need to display this message while executing the task scheduler.
I set up the windows task scheduler to run daily once.
But instead of showing the message written in the load event of the aspx page it is opening the vbscript file .
Can anybody please help me on how to schedule this task on windows task scheduler? and is it possible to use javascript file instead of vbscript for scheduling the task?
Thanks
Priya
check http://www.emoreau.com/Entries/Articles/2004/08/Interfacing-the-Windows-Task-Scheduler.aspx (and the comments at the bottom of the page)
I've found that using the SCHTASKS utility is a really good way of managing scheduled tasks.
'Creates a schedulded Task to run 2 minutes from NOW
'You can manually set the start time by using the following format:
'
'strStartTime = 21:30:00
'
Set objShell = CreateObject("Wscript.Shell")
strComputer = "."
'************************
'Run 2 Minutes from Now
'************************
datDate = DateAdd("s", 120, Now())
datLongTime = FormatDateTime(datDate, 3)
If Instr(datLongTime, " PM") Then
strStart = Replace(datLongTime," PM","")
arrStartTime = Split(strStart, ":")
strHour = arrStartTime(0) + 12
Else
strStart = Replace(datLongTime," AM","")
arrStartTime = Split(strStart, ":")
strHour = arrStartTime(0)
End If
strStartTime = strHour & ":" & arrStartTime(1) & ":" & arrStartTime(2)
'************************
'Schedule the Task
'************************
strCommand = "schtasks /create /tn ""Task Name"" " & _
"/tr ""C:\MyScript.vbs"" /sc once /sd 09/21/2010 /st " & strStartTime & " /ru Domain\JSmith /rp Pa$$w0rd /f"
objShell.Run(strCommand)
Does your Task Scheduler show the file in Notepad or some other editor?
If so, you probably want to change the program in your scheduled task to something like:
wscript.exe c:\myscript.vbs
Some admins change the default behavior of scripts to open in NOTEPAD to prevent malicious code from entering the environment and running if someone just clicks on it.
If so, you probably want to change the program in your scheduled task to something like:
wscript.exe c:\myscript.vbs
Some admins change the default behavior of scripts to open in NOTEPAD to prevent malicious code from entering the environment and running if someone just clicks on it.
ASKER
The file is opened in the notepad itself.But it is not opening the aspx page
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you please make it more clear for me? Do i need to change the vb script file?
My vb script is(script file name is HttpRequester.vbs)
-------------------------- ---------- ---------- ---------- ---------- -
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XM LHTTP")
URL = "http://localhost:59393/TaskScheduler.aspx"
objRequest.open "POST", URL , false
objRequest.Send
My vb script is(script file name is HttpRequester.vbs)
--------------------------
On Error Resume Next
Dim objRequest
Dim URL
Set objRequest = CreateObject("Microsoft.XM
URL = "http://localhost:59393/TaskScheduler.aspx"
objRequest.open "POST", URL , false
objRequest.Send
ASKER
Helped me reolve my issue