Custom Executes
- Updated2024-03-28
- 3 minute(s) read
Custom Executes
Custom executes are executables or batch scripts that can be run during a package transaction.
There are six types of custom executes:
- Pre Install: Runs before a single package installs.
- Post Install: Runs after a single package installs.
- Post All Install: Runs after all packages in an install transaction have completed.
- Pre Uninstall: Runs before a single package uninstalls.
- Post Uninstall: Runs after a single package uninstalls.
- Post All Uninstall: Runs after all packages in an uninstallation transaction have completed.
Root and Relative Path
Root is the root directory where the custom execute will be located. A relative path from the root to the executable can be specified in the relative executable path. The relative executable path is either just the executable name, if the executable is located immediately under the root, or a relative path from the root to the executable.
Examples
Example 1
Root: [Program Files (64-bit)] Relative Executable Path: foo.exe
Typical path: C:\Program Files\foo.exe
Example 2
Root: [Program Files (64-bit)] Relative Executable Path: relative\path\foo.exe
Typical path: C:\Program Files\relative\path\foo.exe
Arguments
Every custom execute can define arguments to be passed into the executable. These can be literal arguments or macros surrounded by the % character. Use quotation characters to surround arguments that contain space characters.
Macros
Macros will be replaced when invoking the custom execute. In the example below, the path to the public desktop replaces %desktop% and a 1 or a 0 replaces %rebootpending%, indicating whether the package will require a reboot to install properly.
-open "%desktop%\file.txt" -reboot %rebootpending%
Refer to Installation Target Roots for File Packages in the NI Package Manager manual for a list of supported directory macros.
Target roots for specific NI software directories must be prefixed with ni-paths-".
Quotations
Surround an argument with quotations if it contains any spaces. In the example below, the executable reads the path 'C:\path with spaces\' as one argument instead of three separate arguments.
-open "C:\path with spaces\"
Options
You can select the following three custom execute options within the Custom Execute dialog:
- Wait to complete: The transaction waits for the custom execute to complete.
- Ignore errors: The transaction does not fail if the custom execute returns non-success.
- Show console window: A console window opens for command line executables and batch scripts.
Post All Custom Executes
If two or more installed packages define custom Post All executes with the same executable name and arguments, NI Package Manager will only invoke one of them.
Calling cmd.exe
Call cmd.exe and specify the /c option within a custom execute to invoke a Windows CMD shell. The custom execute invokes the specified command/executable program passed as an additional argument.
Example 1
Root: [System(64-bit)] Relative Executable Path: cmd.exe Arguments: /c ""%Temp%\MyTempFile.bat""
Calls a batch file installed by the package to the [Temp] directory.
Example 2
Root: [System (32-bit)] Relative Executable Path: cmd.exe Arguments: /c ""%Program Files_64%\MyTempFile.bat" "parameter 1" "parameter 2""
Debugging Custom Executes
If NI Package Manager cannot locate the executable specified by the root and relative path, it displays the following error message:
An error occurred while installing package 'package-name'.
To debug the executable, configure the custom execute to call cmd.exe and specify the path to the executable in the argument. When calling cmd.exe, enable the 'Show Console Window' option, and specify /k instead of /c to see any status reports from cmd.exe. Enter the exit command to close the console window when debugging with the /k option.
In This Section
Related Information
- Common Tasks
Refer to the following tasks for step-by-step guidance for creating or editing a new or existing package-based distribution.
- Installation Target Roots for File Packages