Using WiseScript to Manage the Delivery Time Logic of SVS Applications, Part 1

Using WiseScript to Manage the Delivery Time Logic of SVS Applications, Part 1

When discussing application virtualization, we often talk about the value of bypassing a conventional installation process. Avoiding complex conditional logic, file copies and registry edits means a faster, less disruptive and more reliable delivery of the application. Put another way, Altiris Product Manager Scott Jones describes an SVS Virtual Software Package as, "a pre-installed, pre-configured, known-good implementation of an application; an 'application image,' if you will; every machine gets the exact same implementation of the app; it's the ultimate in standardization."

But what about those situations when there's "install-time" logic that you want to retain? For example, machine- or user-specific info that must be set in order for the app to function correctly? SVS OnEvent Actions allow you to embed delivery-time logic in a VSP, just as would in an MSI. And WiseScript from Altiris is the perfect tool for doing it!

Introduction

In this article we go through the process of customizing the behavior of an SVS package using WiseScript. WiseScript is a simple, yet versatile scripting language that consolidates dozens or hundreds of lines of code into predefined script actions. Since I was introduced to WiseScript, I have to say, it's grown on me more and more. WiseScript is a quick and easy to use tool that can bring customized control to how your SVS applications perform.

In this example, we will create a "Post Activation" event for our SVS package using WiseScript to display an End User License Agreement (EULA) and to set a registry key with its acceptance for the currently logged on user.

Prerequisites:

This tutorial assumes that you have a basic knowledge of WiseScript and the Wise Virtual Package Editor.

Preparation:

In preparation for this project, I have done the following:

  • Captured "FireFox 1.5.0.3" into a Wise Virtual Package (.wvp) project using the Wise Virtual Package Editor.
  • Created a "firefox_eula.txt" file that contains the terms of the End User License Agreement.

The first thing we are going to do is launch the Wise Virtual Package Editor and open our "FireFox 1.5.0.3" (.wvp) project file. Select the Package Settings > Events Page. Then select the "Post Activation" option from the Event dropdown list.

Next press the "Add" button and select the "WiseScript..." option to bring up the WiseScript Editor.

Now we can create our script to run on "Post Activation" of the FireFox SVS Layer. First thing we need to do is declare a few variables and set them with default values. Add a "Set Variable" action to your WiseScript, name it "LAYER_NAME", and set the Value to "Firefox 1.5.0.3".

Create another variable named "LAYER_GUID" and set the Value to an empty GUID "{00000000-0000-0000-0000-000000000000}"

Next we need to add a "Find SVS Layer GUID" action to our WiseScript. Set the layer name to the value of our %LAYER_NAME% variable, and set the GUID variable to LAYER_GUID which will over write the empty GUID value that we set as the default value. (Optional: You can specify a variable to store the return code in, but we are not checking the return code in this example).

Next we need to validate that the SVS Layer GUID was found by creating an "IF Statement". If the value of LAYER_GUID still equals the empty GUID "{00000000-0000-0000-0000-000000000000}" then it was not able to find the active SVS Layer GUID for the FireFox layer.

Add a "Display Message" action informing the user that the layer was not found.

Add an "Exit installation" action, setting the Application Exit Code to any desired value.

Then close the "If Statement" with an "End Statement" action resulting in the following completed "If Statement":

Now we are going to add a "Get Registry Key Value" action to the script to perform a check for the EULA acceptance key. Name the variable "REG_CHECK" to store the resulting value in, set the default value to "0", enter the registry key path and value name of the EULA acceptance key, and set the Root to "HKEY_CURRENT_USER".

Next we are going to create another "If Statement" to determine what actions to perform based on the REG_CHECK returned value. If the acceptance registry key has the value of "1", the EULA has been accepted and the script completes leaving the layer active. If the registry key is not found, the remainder of the WiseScript will be executed and the user will be prompted with the Firefox EULA dialog.

Add an "If Statement" to verify that the Variable REG_CHECK Does Not Equal "1".

Now we are going to add all the remaining actions for this script within this REG_CHECK "If Statement" (Note: we will be adding the "End Statement" for this "If" Block at the very end of the script). The first thing we are going to do within this "If Statement" is to add a "Get Temporary Filename" action in preparation for displaying the EULA text file. Set the variable name to "EULA".

Next add an "Install File" action to install the "firefox_eula.txt" file. Browse and select the "firefox_eula.txt" file. Set the Destination Directory to "%TEMP%\%EULA%". This will install the "firefox_eula.txt" to the user's temporary files folder under the temporary filename we created and assigned to the EULA variable. This will allow an automated clean up of the installed file because temporary files get removed automatically on reboot. And finally check the "No progress bar" setting for this dialog.

Now we are going to display our custom EULA Dialog. Add a "Custom Dialog" action to the WiseScript to open the Custom Dialog Editor.

In this custom EULA dialog, add an "Edit Text" control to display the EULA text. You can play around with the various settings to get the desired look, behavior, and size. Set the "Read Default Text From File" field to the path of the temp EULA file we are installing "%TEMP\%EULA%".

Next, add a radio button control to the dialog for the "Accept" and "Not Accept" options. Add the text you wish to display, create a variable "AGREE" to hold the selected value in, name the control "ctrl_Agree", and set the desired position and size.

Lastly we will add an "OK" button to the dialog, setting the action option to "Return to Script".

Add any additional information and graphics that you want to customize your new Software License Agreement dialog. Then close the custom dialog editor to return to the main WiseScript.

Now that we have our custom EULA dialog, we need to add the functionality to the script to determine what actions are to be taken based off of the returned value stored in the AGREE variable. To do this we are going to create a multi-option "If / ElseIf Statement". (We will create the whole If / Else statement block first, and then fill in the appropriate action for each option).

Add an "If Statement" action to check if the value of the AGREE variable equals "B" ("B" is the value of the "Do Not Agree" radio button option).

Add an "ElseIf Statement" action to check if the value of AGREE equals "A" ("A" is the value of the "Agree" radio button option).

Next, add an "Else Statement" to be our remaining "Catch All" action in case we are unable to determine the value of the AGREE variable.

And then add an "End Statement" action to complete the "If" Block, resulting in the following script actions:

Now we can add in the actions to be performed for each option. Under the first "If Statement" (Not Agree), add a "Display Message" action telling the user that they will not have access to use Firefox until they accept the EULA.

Next, add a "Deactivate SVS Layer" action. Set the Layer GUID to the value of the %LAYER_GUID% variable and check the option to "Force running processes to terminate". This ensures that the users cannot use the SVS application without accepting the End User License Agreement.

Now let's move to the "ElseIf Statement" (Agree) section. Add an "Edit Registry" action to set the EULA acceptance registry key to the value of "1" for the current user. (Note: if the registry key does not exist it will be created).

And then we will move to the last "Else Statement" that will be used for our "Catch All" situation (although, the script should never get to this section). Under the last "Else Statement", add a "Display Message" action telling the user that it was unable to determine the answer of acceptance for the EULA.

Then add a "Deactivate SVS Layer" action. Set the Layer GUID to the value of the %LAYER_GUID% variable and check the option to "Force running processes to terminate".

Now let's complete the REG_CHECK "If Statement" by adding another closing "End Statement" to complete the WiseScript.

Your final WiseScript should look something along these lines:

Then lastly, Click "Ok" on the WiseScript Editor dialog to add the script to the "Post Activation" page of your (.wvp) project. Now its time to compile and test our project.

Once compiled, import your .VSA package into SVS and activate the layer. Upon activation you should get prompted with the new custom EULA dialog we created:

Select the "Do not accept" option and click "OK". You should see your "Do not agree" display message and the layer should then Deactivate.

Now activate the layer again and choose the "I Accept" option. You should have full access to the virtual application now.

To test to make sure that the user only has to accept the EULA once, Deactivate and Reactivate the layer. You should still have access to the application without any additional prompts for accepting the EULA. You can also check the registry to verify the existence of your EULA acceptance registry key.

In conclusion, as you can see, with using just a short WiseScript, we can control, enforce, and manage the behavior of our SVS virtualized applications quickly and efficiently. I hope this tutorial has been useful and by no means is this the limit of what you can achieve with a simple WiseScript.

Thank you,
Aaron Phillips

4
Average: 4 (36 votes)
Syndicate content