I always wondered how to run scheduled tasks on windows hosting. For example, under the Plesk control. At first look, everything is ok. We have scheduled task and "command line" for it. But what to write there in the command line? This is the big question.
Somebody says - no problem, I'll write "iexplore http://example.com/track.aspx"
But I'm wondering, who closes this Internet Explorer process on server, and what if you are going to run this task every 5 minutes?
I don't like this way. So, where is the answer? Answer is inside VB. All that we need is to create VB script and run it inside command string.
This script creates
Microsoft.XMLHTTP instance (yes, we don't need to check anything like in AJAX deal, because we are certainly in Microsoft environment). And using this instance requests your ASPX page to do the entire job.
So, when I've asked my hosting support, how to call aspx page scheduled - they said - this is impossible. Call PHP page and there request your ASPX if you want. No, thanks.
Using the Code
Plesk screen... to add scheduled task. "Path to executable" should be set to ABSOLUTE path to vbs file on server. Where can you get this path... First of all, your hoster should give you information about your site's folder. If not, write a simple aspx page with
Server.MapPath("my.vbs"); So, what's inside the VB file?
On Error Resume Next
Set RequestObj = CreateObject("Microsoft.XMLHTTP")
URL = "http://www.example.com/track.aspx"
RequestObj.open "POST", URL , false
Set RequestObj = Nothing
That's all. And you can run the scheduled task. Plesk is just for example... you can use Windows schedule if you've terminal access to the server.
Points of Interest
This is a simple thing, but I better say "trick" that can help you to solve the problem of scheduled task.
Originally posted on my site.
Works fine on several sites for daily content updates.