Home page rotator
Written by Ian Elliot   
Tuesday, 09 February 2010
Article Index
Home page rotator
Setting up the system
Custom menu for IE and using the scheduler
Running the script

Setup

Now we have the broad outline it is time to get to work. As everything is going to be in VBScript, which is easy to convert to JScript if you want to, we don't need any language environments installed. It is, however, worth making sure that you have the latest version of the Windows Scripting Host and script engines installed – check on the Microsoft website.

You can also create and modify all of the scripts using nothing but Notepad or you can use an editor such as Visual Web Developer Express edition (which is free to download from the Microsoft website).

As the whole system is composed of a number of scripts we really need an installation script that will set everything up and an uninstall script to return everything to how it was. As the setup script does a great deal of the hard work this seems like a good place to start.

Create a folder where you are going to store all the scripts relating to this project – it doesn't matter what it's called or where it is. A good setup program should be able to install everything irrespective of the location of the project resources. Create a file called Setup.VBS in the directory.

It's a good idea to give the user a chance to change their mind before installing:

button=Msgbox("You are about to setup
Home Page Rotator –
click OK to continue or
Cancel to abort",1)
if button = 1 then
Setup
Msgbox "setup complete"
else
msgbox "Setup cancelled-run setup again
to install or refresh an installation"
end if

Now we have all of the work being done by the Setup subroutine. The subroutine divides into three parts –

  • create folders and copy files
  • set up favourites
  • set up the schedule

To do all this we need two auxiliary objects – the WshShell object which provides ways of interacting with the system and the FSO object which provides ways of interacting with the filing system:

Sub Setup
'create folders and copy files
Set WshShell = _
WScript.CreateObject("WScript.Shell")
set fso=CreateObject( _
"Scripting.FileSystemObject")

We need to find out where the user's program folder and System32 folder are. It would be simpler just to assume their standard names but it isn't very much extra work to ask the system for them just in case they are non-standard. The key to this is to read the environment variables:

'Get folder names
Set WshSysEnv = _
WshShell.Environment("PROCESS")
ProgFolder=WshSysEnv("ProgramFiles")
ProgFolder =ProgFolder &
"\HomePageRotator"

This gets the program folder's name, usually Program Files, and adds the name of the directory we are going to use to store all of the applications files, i.e. \HomePageRotator. Originally it was planned that this would store the entire installed project but it turned out that it was much easier to put the scheduled script into the System32 folder to avoid having to specify a path. The full name of the System32 folder can be found using:

Set WshSysEnv = _
WshShell.Environment("PROCESS")
Sys32=WshSysEnv("SystemRoot") &
 "\System32"

Finally we need the current directory where all of the project files, including the setup script, are stored:

currentdir= WshShell.currentdirectory

If the project folder doesn't exist we need to create it:

if not(fso.folderexists(ProgFolder)) then
fso.createfolder(ProgFolder)
end if

Now we can copy the two key project files starting with the script that is triggered when the user selects the custom item in Explorer's context menu:

fso.copyfile currentdir & _
"\HR.htm",ProgFolder & "\",true

This script has to be stored in an HTML file and exactly what it does will be explained later but essentially it creates the list of home pages that we want to rotate.

The second script is the one that uses the list to move on to the next home page each time it is triggered:

fso.copyfile currentdir & _
"\rotate.vbs",Sys32 & "\",true

This script, rotate.vbs, is a standard VBScript and again we will return to how it works later.

<ASIN:0596004885>

<ASIN:0470168080>

<ASIN:0735622442>



Last Updated ( Monday, 08 February 2010 )