Click here to Skip to main content
15,881,380 members
Articles / Web Development / ASP.NET

Scheduled Task in Middle Trust Enviroment

Rate me:
Please Sign up or sign in to vote.
3.30/5 (4 votes)
11 Dec 2007CPOL2 min read 26.9K   7   2
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?

VBScript
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)


Written By
Web Developer
Ukraine Ukraine
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThis worked for me Pin
Benjano13-Jul-12 1:15
professionalBenjano13-Jul-12 1:15 
QuestionPath? Pin
xirc_za17-Jul-09 12:13
xirc_za17-Jul-09 12:13 

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

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