Click here to Skip to main content
Click here to Skip to main content

Scheduled Task in Middle Trust Enviroment

, 11 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
Explains how to setup scheduled task on Windows hosting through Plesk CP

Introduction

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?

Call RunIt()
Sub RunIt()
        'Let the script to finish on an error.

        On Error Resume Next
        Dim RequestObj
        Dim URL
        Set RequestObj = CreateObject("Microsoft.XMLHTTP")
        'Request URL... 

        URL = "http://www.example.com/track.aspx"
        'Open request and pass the URL

        RequestObj.open "POST", URL , false
        'Send Request

        RequestObj.Send
        'cleanup

        Set RequestObj = Nothing
End Sub        

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.

History

Originally posted on my site.

Works fine on several sites for daily content updates.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dmitry Salko
Web Developer
Ukraine Ukraine
No Biography provided

Comments and Discussions

 
GeneralThis worked for me PinmemberBenjano13-Jul-12 1:15 
QuestionPath? Pinmemberxirc_za17-Jul-09 12:13 
Hi,
 
I know this article is old, but the guys that supply hosting to me is not very helpful.
 
I need to know:
 
Path to executable * ?
 
Arguments ?
 
Can you please give me an example thanks.
 
Then do they allow execution of .exe files?
 
Would it not be better to rather run the task as executable?
 
Thank you so much...

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.141029.1 | Last Updated 11 Dec 2007
Article Copyright 2007 by Dmitry Salko
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid