Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Scheduling a task with VB Script and Windows Task Scheduler.

Posted on 2010-09-21
7
Medium Priority
?
1,012 Views
Last Modified: 2012-05-10
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.XMLHTTP")
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("TaskScheduler.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

0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33723651
0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 33725453
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)

Open in new window

0
 
LVL 17

Expert Comment

by:Tony Massa
ID: 33725542
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:netdesignscs_sunnyvale
ID: 33726002
The file is opened in the notepad itself.But it is not opening the aspx page
0
 
LVL 17

Accepted Solution

by:
Tony Massa earned 750 total points
ID: 33726082
It can't since it's not running in the correct environment.  Change your program to run wscript with the script path + name as the argument in Task Scheduler.
0
 

Author Comment

by:netdesignscs_sunnyvale
ID: 33726248
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.XMLHTTP")
URL = "http://localhost:59393/TaskScheduler.aspx"
 objRequest.open "POST", URL , false
objRequest.Send



0
 

Author Closing Comment

by:netdesignscs_sunnyvale
ID: 33727101
Helped me reolve my issue
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question