Following an exchange of ideas with Still_ASP, a loyal reader of the web thought, I thought to write something about scheduling events on a Windows server.
Sometimes we might need to trigger some events independently from the actual opening of a page or a specific action taken by a user. If nobody is browsing your page, how could we trigger an event anyway?
To do so, we need to use a little trick that I will shortly explain.
Schedule an event
In a Windows environment we can schedule tasks using Windows Scheduler. In this article I won't explain how to use the tool, because I assume we all know how to do it. It is enough to say that we can schedule any task we want: backups, running programs, killing of specific tasks, opening of web pages and so on.
As you may foresee, we can use Windows Task Scheduler in order to open a specific ASP page, wait for it to end its tasks and then close it. And we are going to use VBScript.
Prepare the fileIn a place we prefer, we need to create a new text file. Right click in an appropriate folder and select New->Text Document. Change the new file extension to ".vbs" and give the file an appropriate name. That is because we need to use VBScript and you will notice that the file icon will change to some sort of blueish paper scroll (is it a magic scroll?).
Now we open the file with a text editor (or whatever you prefer) and we start writing the VBScript code.
The VBScriptThe code's quite simple. We are going to open a specific web page in Internet Explorer, wait for it to complete the task and then we close the program.
Insert the following code into the vbs file:
Let me explain what the code is doing.
Set objIE = CreateObject("InternetExplorer.Application")
objIE.visible = true
Set objIE = Nothing
It creates an object for Internet Explorer, and thus it opens the program. Then it opens the Google web page. We have to be sure that IE is visible (objIE.visible = true).
The code waits while the IE object is busy and just when IE finishes the task (and the web page has been loaded), the code exits IE and set the object to nothing.
It is very simple, isn't it?
Now that we have the file ready to be used, just double click on it and see what happens. If everything is ok, just create a scheduled task that will open the file and we are done.
I hope that you have found the information useful!