Hi all! It’s been a few days since my last post about wrapping our update mechanism around your application and it’s time for some web server code samples; but first, I wanted to make an enhancement to the update script.
If we want to change our “Run Program As” commands, we’ll have to edit multiple parts of the update script. At best, this is tedious; typically it will introduce errors with forgotten or misplaced commands. The solution is simple: we’ll use the Label and GoTo Label MSIcode commands to create a re-usable region of code. This way, we’ll remove all pairs of existing “Run Program As” and “Terminate Installation” commands, replacing them with a GoTo Label command that points to a new “Label” called “RunProgramSection“, with the “Run Program As” and “Terminate Installation” commands underneath.
So now, instead of making changes all over the place in the MSIcode script, I only have to make one change under the Label command. That way, I can re-use this code block in other projects:
I can also build in more sophisticated behavior, adding more MSIcode commands. Lets say you want to run two programs – one might be a tray application and the other one the “real” application.
Quite easily done. Extensibility and scalability are everything these days!
And now for some server side code. First, please make sure you’re familiar with a server side scripting language like PHP or ASPX. Please visit www.asp.net and www.php.net if you need a jumpstart. I’ll assume that you’ve done your homework and that you can follow the simple scripts provided below.
First some PHP. If you remember, I pass some parameters from my MSIcode InstallAware setup/client script to the web/server script as URL parameters. In PHP, URL parameters are stored inside a predefined variable called $_GET, which is a global array. If you want to read a user’s serial number and your parameter is called serial, you can try the following:
$serial = strip_tags($_GET['serial']);
Now, the PHP script variable $serial has our parameter’s value. Let’s see if the serial number provided is actually valid:
if ( CheckIfLegimitate($serial) )
If the serial is valid, the PHP script above returns “1″, or “0″ otherwise. Either way, the return value is appended with a comma delimited random number. Back on the InstallAware setup/client side, I read this value using the “Download File” MSIcode command, and I then parse it using Parse String; which lets me obtain both the status code (“1″ or “0″), and of course the random number.
Next post: Database schema scripts and more code. It’s going to be the last post from these series so, stay tunned!
Software Design Team Lead
InstallAware Software Corporation