How do I use WiseScript Wrappers to perform multiple tasks?
Note: This article was originally published in the November 2002 TechInfo! Newsletter. The information contained in this article is accurate for the products referenced, and has not been updated for later product releases.
WiseScripts are extremely versatile and can be adapted for a wide variety of purposes. One common application uses a WiseScript to execute several script-based and Windows Installer (.MSI) installations. These scripts, referred to as "wrapper scripts," allow one or more installations to be wrapped into a single script. The single script can perform additional tasks such as executing other utilities, running batch files, and installing prerequisite software or runtime engines.
Several common issues can appear when creating wrapper scripts, and you can use WiseScript actions to address them. This article answers common questions that arise when creating installation wrappers with WiseScript. To follow the questions and answers below, open your installation in Wise Installation System, WiseScript Editor in Wise Package Studio, or in WiseScript in Wise for Windows Installer and Wise for Visual Studio .NET.
How do I execute installations within a wrapper script?
Within the wrapper script, use the Execute Program script action to run other WiseScript .EXE installations or .EXEs. To accomplish this, follow the procedures below:
- In the Script Editor, double-click the Execute Program script action. The Execute Program Settings dialog appears.
- In the Executable File field, enter the full path name and executable of the file you want to run.
- In the Command Line Arguments field, enter any command line switches to pass to the .EXE.
- Mark the Wait for Program to Exit checkbox if you want the wrapper script to wait for the .EXE to finish before continuing with the remainder of the wrapper script. If you are expecting a return value from the .EXE, mark this checkbox.
- Depending upon the purpose of your .EXE, you may wish to enter values in the Default Directory and Window Size fields as appropriate. For more information on these fields, see the topic titled Execute Program in the Wise Online Help.
If you are using the Execute Program script action to launch an .MSI installation instead of an .EXE, configure the action as follows.
- In the Executable File field in the Execute Program dialog, enter %SYS%\msiexec.exe.
- In the Command Line Argument field, enter the parameters to perform the action on the .MSI. For an initial installation of an .MSI file, enter /i PathToMSI.msi".
- If you want the WiseScript wrapper to wait for the .MSI installation to finish, mark the Wait for Program to Exit checkbox.
How do I handle returns within a wrapper script?
To obtain the return value from an Execute Program action, use the PROCEXITCODE WiseScript variable. This variable is automatically defined after each Execute Program script action and contains the return value from that .EXE. Although this variable is automatically defined, you still need to initialize it before using it in your WiseScript wrapper. To initialize the variable, use the Set Variable script action and set the PROCEXITCODE to any value.
Using this return value enables you to determine various courses of action depending on whether the called installation succeeded, failed, or returned any other status.
How do I handle reboots within a wrapper script?
Installations often require the system to reboot before proceeding. If any of the installations called from the wrapper script require a reboot, the main wrapper script must handle this for the installation to continue after the system restarts. Two possible methods for rebooting with the wrapper script are listed below:
Rebooting with a wrapper script option 1:
Place a shortcut to your WiseScript wrapper .EXE in the StartUp folder so it launches after a reboot. Next, use internal script logic to determine exactly where execution of the wrapper script occurs after each reboot. For example, suppose a wrapper script installs two packages, Package1 and Package2. You can include checks to see if each package is installed and, if so, then skip those installations and continue until all installations finish executing. There are several ways you can check to see if the packages are installed:
- You can invoke the Check If File/Dir Exists script action to verify whether a specific file exists, and use this to indicate whether the installation was successful.
- You can use the Get Registry Key Value script action to check for a specific registry value from the Package1 and Package2 installations.
- You can check a counter that is incremented by the wrapper script before each installation executes.
Use the information gathered from the check to construct conditional statements to control the execution of the Package1 and Package2 installations. Below is some "pseudo code" of how these statements look.
Create Shortcut in StartUp folder to WiseScript Wrapper EXE
Check if Package1 is installed
If Package1 is NOT Installed Then
Execute Program to install Package1
Check if Package2 is installed
If Package2 is NOT Installed Then
Execute Program to install Package2
Delete Shortcut in StartUp folder
Rebooting with a wrapper script option 2:
Populate the value of the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce registry key with the path to the WiseScript wrapper executable and pass it different command line parameters to mark the position where execution continues in the wrapper script if a reboot occurs. In the wrapper script, check the %CMDLINE% variable to obtain the command line switches that are passed in and to create conditional statements based on this value. Below is "pseudo code" for an example of a WiseScript wrapper that installs three packages.
Set Variable POS = 0
If %CMDLINE% Contains "/POS" Then
Rem Parse everything after /POS into a variable POS
Parse String "%CMDLINE%" into JUNK and POS
Rem Parse %POS% to obtain the next character into POS
Parse String "%POS%" into POS and JUNK
If %POS% Less Than or Equal "1" Then
Write RunOnce Key = "PathToWrapper.EXE /POS2"
Execute Program to install Package1
If %POS% Less Than or Equal "2" Then
Write RunOnce Key = "PathToWrapper.EXE /POS3"
Execute Program to install Package2
If %POS% Less Than or Equal "3" Then
Execute Program to install Package3
Remove RunOnce Key
Option 1 and option 2 are two very common methods for tracking the progress of your WiseScript wrapper script across multiple reboots. There are many other options available as well. Keep in mind that when a specific installation requires a reboot, no return value is likely to be passed back to the WiseScript wrapper because of the reboot. If you need to verify the success of an installation, perform any checks after the reboot has occurred.
In addition to performing installations, a WiseScript wrapper can handle any installation prerequisites. For example, a WiseScript wrapper can pre-install specific runtimes or make changes to the system configuration before initiating installations.
The wide range of script actions available with WiseScript allows you to perform a variety of tasks including performing installations, modifying system configurations, running various utilities, handling potential errors and reboots, and verifying all installation tasks have been completed. With this type of versatility, you can use WiseScript to automate almost any set of tasks.
Rate this Article