The Package Scripts Page
The Package Scripts page displays the Pre-Script, Command Line Script, and Post-Script when applicable.
To display the Package Scripts page, click on the Scripts folder within the selected package in the left pane.
The following list describes the Package Scripts page fields and their functions.
Properties |
Description |
---|---|
Execution directory |
Displays the directory under which the selected script will execute, preventing the need for full paths in the script. |
Type |
Defines the script. The options available are:
|
Template |
Available for Post-Script type only. Provides an easy way to create scripts on Windows-based patches using simple .msi- or .exe- based software installation programs. For more information, see Using a Template to Add a Package Script. |
Deployment Script |
Contains the actual script to be executed. |
Types of Package Scripts
There are three types of package scripts. These scripts can be written in Microsoft Visual Basic Script or Microsoft JScript.
For more documentation on scripting languages, refer to Introduction to Windows Script Technologies (https://docs.microsoft.com/en-us/previous-versions/tn-archive/ee176792(v=technet.10)).
A software package can have a maximum of one of each type of script. When all three scripts are present, they will be executed in the following order:
- Pre-Script: Tests for a condition or shuts down a service on a computer or device. If you're going to use command line scripts, you must enter a Pre-script, which should set return code values for PLCCAgent.SetReturnCode. These values are used later to return deployment results back to the Agent. See the code example below.
Copy
' Create The Objects
Set Shell = CreateObject("WScript.Shell"): Set FSO =CreateObject("Scripting.FileSystemObject")
Set windir = FSO.GetSpecialFolder(0)
If Err.number Then
EMsg = "An error while attempting to create the required objects." & vbNewLine & _
"Error Number: " & Cstr(Err.number) & vbNewLine & "Error Description: " &
Err.Description & vbNewLine & vbNewLine
& _
"NOTE: Please verify that you have Windows Scripting Host 2.0 or higher installed."
Err.Clear
Else
'Do other functions
End If
'Stop deployment for error
If LenB(EMsg) Then
PLCCAgent.SetReturnCode 1, EMsg
Else
'Success
PLCCAgent.SetReturnCode 0, vbNullString
End If - Command Line Script: Starts executable files. The format is the same as a standard.cmd or .bat file.
-
Post-Script: Performs operations such as the deletion of files, starting services, or running an installer.
You can substitute any error code listed on Microsoft Docs in place of '1' to produce a more specific error message.
Unless the Execution directory option is selected and a valid directory is defined, all scripts run in the ROOT directory.
Editing a Package Script
You can create or edit a package script from the Package Scripts page.
Prerequisites:
A package for the patch has been created. Refer to Adding Packages for additional information.
Edit existing package script properties from the Package Scripts page.
- Expand the patch properties to Scripts in the left pane.
Example: New Patch > Signatures > New Signature > Package > New Package > Scripts.
The Package Scripts page opens. - In the left pane select Scripts.
- Define the directory location.
- Select the Execution directory check box.
The associated directory field becomes active. - Type the directory location from which the selected script will execute in the associated directory field.
- Select the Execution directory check box.
- Select the script type drop-down list items based on your needs. The following table describes each script type.
- [Optional] Use the Launch Editor to create a script.
- Click Launch Editor.
A text editor opens. - Edit the script as desired.
- Select File > Save.
The text is saved. - Select File > Exit.
The text editor closes and the text displays within the Deployment Script panel.
- Click Launch Editor.
- Click Validate.
The package script is validated and a validation message appears. - Click OK.
The validation message closes.
Type |
Script Language |
Description |
---|---|---|
Pre-Script |
|
Test the condition on the machine. |
|
VB Script |
VB Script Language option. |
JScript |
JScript Language option. |
|
Post-Script |
|
Performs operations, deletes files, starts services, or open installers. |
|
VB Script |
VB Script Language option. |
JScript |
JScript Language option. |
|
Command Line Script |
|
Starts executable files. The format is the same as a standard .cmd or .bat file. |
Tip: The Template button is available for the Post-Script type only and provides an easy way to create scripts on Windows-based patches using simple .msi- or .exe-based software installation programs. For more information, see Using a Template to Add a Package Script.
If a script error occurs, use the text editor to fix the script content prior to continuing.
The package script is edited.