Schedule ASP pages to run in Task Mgr.

One of the most common questions I've seen on forums is "How do I schedule my ASP page to run at a specific time?". The solution is extremely simple and involves using the Microsoft XML Parser and the XMLHttp object.

One of the most common questions I've seen on forums is "How do I schedule my ASP page to run at a specific time?". The solution is extremely simple and involves using the Microsoft XML Parser and the XMLHttp object.

I've also used the Windows Scripting Host to accomplish this task in similar fashion. However, I've found that if you are logged onto the server at the time of the job, the IE browser pops up at times. Plus, the XMLHttp object seemed to work cleaner and provide an easy way to return whether we were successful or not.

Simply create a small .vbs (VBScript) file with the following code as its content. Then, create a scheduled job in windows task manager using the .vbs file as the script to be run. It's that simple!

However, there is one small item that may cause you problems. Even if you run the scheduled job under a specific user, IE may still attempt to bring up the standard username/password/domain prompt. I suggest creating a special user to access your protected folder on the server specifically for scheduled jobs. I've included
as part of the sample a way to get around that without special NTLM code. Just be sure that others don't have access to download your .vbs file.

Sub MyASPJob()

Dim oXMLHttp
Dim sURL

on error resume next

Set oXMLHttp = CreateObject("MSXML2.XMLHTTP.3.0")
sURL = "http://usr:pwd@www.mysite.com/job.asp

oXMLHttp.open "GET", sURL, false
oXMLHttp.send()

if oXMLHttp.status = 200 Then
' Retrieve enter HTML response
MsgBox oXMLHttp.ResponseText
else
' Failed
end if

Set oXMLHttp = nothing

End Sub

Call MyASPJob()


Submission Date:  9/23/2005 2:51:24 PM
Submitted By:  Robbe Morris
My Home Page:  http://www.robbemorris.com

By Robbe Morris   Popularity  (417 Views)
Picture
Biography - Robbe Morris
Robbe has been a Microsoft MVP in C# since 2004. He is also the co-founder of NullSkull.com which provides .NET articles, book reviews, software reviews, and software download and purchase advice.  Robbe also loves to scuba dive and go deep sea fishing in the Florida Keys or off the coast of Daytona Beach. Microsoft MVP