Back to Blog Listing
When writing web applications, its common to want to have some code run at scheduled times – e.g. to synchronise an update. As the main body of the code is in a web application, and there is no distributed code, the easiest place to implement the code is inside the web application, perhaps with a web service or a simple web page as the interface.
Windows comes with a tool that allows programs to be scheduled to run as desired – Task Scheduler. The Task Scheduler can be used to call the web page. Often, developers start Internet Explorer from Task Scheduler and ask it to visit the web page URL. However, this can be problematic – sometimes IExplore.exe does not shut down and after a few Tasks IExplore never actually visits the web page, despite the Task history showing as the task executed correctly.
As the full functionality of a browser is not required, there are other techniques that can be used. One that we have found works well is to use Task Scheduler to start powershell.
This is as simple as using IExplore.exe, instead start powershell.
An example of the call with parameters:
powershell -ExecutionPolicy unrestricted -Command "(New-Object Net.WebClient).DownloadString(\"http://domain.com/websiteurl?all=0\")"
This is more lightweight than Internet Explorer and has proven to be reliable.