When editing an update, the Pre-Install / Post-Install Scripting tabs are used to define custom batch commands that will be executed before or after the update is installed. The process is the same for both tabs.
The batch file commands can be defined by typing them in the space provided, or by using the copy and paste commands to input the commands. The following environment variables are available for use in the commands:
This script is an example to expand and display the %PATHTOFIXES% and %LSFN% variables to show the actual values.
Script
@Echo Begin Expand Variables Script>>.\Trace.txt @Echo >>.\Trace.txt @Echo Expand Variable – PATHTOFIXES>>.\Trace.txt @Echo PATHTOFIXES: %PATHTOFIXES%>>.\Trace.txt @Echo Expand Variable – LSFN>>.\Trace.txt @Echo LSFN: %LSFN%>>.\Trace.txt @Echo >>.\Trace.txt @Echo End Expand Variables Script>>.\Trace.txt
Output
Text from the Trace.txt file.
Begin Expand Variables Script Expand Variable – PATHTOFIXES PATHTOFIXES: C:\ProgramData\Lenovo\Lenovo Patch\Installation\InstallationSandbox#2021-08-19-T-15-32-10\ Expand Variable – LSFN LSFN: C:\ProgramData\Lenovo\Lenovo Patch\Installation\InstallationSandbox#2021-08-19-T-15-32-10\lucagent1007.exe End Expand Variables Script
This script is an example on how to stop and disable the Print Spooler service on a device.
Script
@Echo Begin Stop / Disable Service Script>>.\Trace.txt @Echo >>.\Trace.txt @Echo Stop Print Spooler Service>>.\Trace.txt @Echo Command - sc stop SPOOLER>>.\Trace.txt sc stop SPOOLER @Echo Disable Print Spooler Service>>.\Trace.txt @Echo Command - sc config SPOOLER start=disabled>>.\Trace.txt sc config SPOOLER start=disabled @Echo >>.\Trace.txt @Echo End Stop / Disable Service Script >>.\Trace.txt
Output
Text from the Trace.txt file.
Begin Stop / Disable Service Script Stop Print Spooler Service Command - sc stop SPOOLER Disable Print Spooler Service Command - sc config SPOOLER start=disabled End Stop / Disable Service Script
This is a sample script showing how to execute an imported custom .REG file using the Custom Files tab to ensure the file is accessible during the Pre-Install / Post-Install script execution.
Script
@Echo Begin Execute Registry change from .REG file Script>>.\Trace.txt @Echo >>.\Trace.txt @Echo Execute Registry Change>>.\Trace.txt @Echo Command - Regedit /s "%PATHTOFIXES%Registry.REG">>.\Trace.txt Regedit /s "%PATHTOFIXES%Registry.REG" @Echo >>.\Trace.txt @Echo End Execute Registry change from .REG file Script>>.\Trace.txt
Output
Text from the Trace.txt file.
Begin Execute Registry change from .REG file Script Execute Registry Change Command - Regedit /s " C:\ProgramData\Lenovo\Lenovo Patch\Installation\InstallationSandbox#2021-08-19-T-15-32-10\Registry.REG" End Execute Registry change from .REG file Script
This is a sample script showing how to execute an imported custom .PS1 file using the Custom Files tab to ensure the file is accessible during the Pre-Install / Post-Install script execution.
Script
@Echo Begin Execute PowerShell Script using .PS1 file Script>>.\Trace.txt @Echo >>.\Trace.txt @Echo Edit Registry>>.\Trace.txt @Echo Command - PowerShell.exe -Command " . '%PATHTOFIXES%POWERSHELL.PS1'">>.\Trace.txt PowerShell.exe -Command " . '%PATHTOFIXES%POWERSHELL.PS1'" @Echo >>.\Trace.txt @Echo End Execute PowerShell Script using .PS1 file Script >>.\Trace.txt
Output
Text from the Trace.txt file.
Begin Execute PowerShell Script using .PS1 file Script Execute PowerShell script Command – PowerShell.exe.exe -Command " . 'C:\ProgramData\Lenovo\Lenovo Patch\Installation\InstallationSandbox#2021-08-19-T-19-17-07\POWERSHELL.PS1'" End Execute PowerShell Script using .PS1 file Script