PromptToSave parameter and using PsExec -s -i

Trying to use the PromptToSave parameter with the Show-InstallationWelcome to prompt users to save working documents when they select to close running programs.

We deploy using SCCM (system account), so according to documentation, we need to user “psexec -s -i” for PromptToSave to work. But we keep getting an error, “The system cannot find the file specified” for Deploy-Application.exe.

The only way I’ve managed to get it to work is to wrap the installer in a VBScript. Is there a way of doing it without another script wrapper?

Can you share your source code?

Show-InstallationWelcome -CloseApps 'winword' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PromptToSave $true -MinimizeWindows $false

The -PromptToSave paramter works fine when I run Deploy-Application.exe as an admin user, but in system context using PsExec, it can’t seem to resolve the path to the installaion source location and it always errors out saying it can’t find Deploy-Application.exe. These are the program commands I’ve tried:

"PsExec.exe" -s - i -accepteula "Deploy-Application.exe"
PsExec.exe -s - i -accepteula "Deploy-Application.exe"
PsExec.exe -s - i -accepteula "%~dp0Deploy-Application.exe"

This is my VBScript wrapper that get’s it to work:

Dim strScriptRoot
Dim WshShell
Dim intReturn

Set WshShell = WScript.CreateObject("WScript.Shell")
strScriptRoot = CreateObject("Scripting.FileSystemObject").GetParentFolderName(Wscript.ScriptFullName)
strPsExec = chr(34) & strScriptRoot & "\" & "PsExec.exe" & chr(34)
strPsExecArgs = " -s -i -accepteula "
strDeployAppExe = chr(34) & strScriptRoot & "\" & "Deploy-Application.exe" & chr(34)

intReturn = WshShell.Run(strPsExec & strPsExecArgs & strDeployAppExe, 0, True)

**My other concern is that when the user selects to “Defer” the deployment, it registers an exitcode of “0” in SCCM’s AppEnforce.log instead of the expected “60012”.

**Edit 2018.11.21 - Resolved this by parsing the exit code:

Wscript.Quit(intReturn)

Is psexec in your %path% ?

If not where are you storing it and how are you calling it in your PADT power shell?

It’s not being called in the PSADT script.

The -PromptToSave parameter is part of the Show-InstallationWelcome toolkit function.
In the PSADT documentation, it states:

-PromptToSave [<SwitchParameter>]

Specify whether to prompt to save working documents when the user chooses to close applications by selecting the "Close Programs" button. Option does not work in SYSTEM context unless toolkit launched with "psexec.exe -s -i" to run it as an interactive process under the SYSTEM account.

This question might be more of an SCCM question than a scripting one.

Is psexec in your %path% though? Ie can you call it yourself in a cli without specifying a full path to the executable?

I’ve included PsExec.exe with the root folder of the Deploy-Application files.

So what I do before I load my PADT app into an SCCM package is to test it locally.

I launch a powershell session on my test machine using psexec -s -i so I am effectively running powershell in the system context. Then I cd to my PADT directory and I run .\Deploy-Application.ps1 -DeploymentType Install

This way I get verbose logging in the console to try and step through it.

I’d test it this way first, if it works then its definitely an SCCM issue. I’m not at work but Ill check our deployments strings tomorrow. We do have 2 ways, interactive and non-interactive.

Yeah so either:

-DeploymentType Install -DeployMode Interactive

or

-DeploymentType Install -DeployMode NonInteractive

Might help if you share your full script and I can check on a test machine myself. I’ve never actually used the PromptToSave so would be interested to see your use case.

<#
.SYNOPSIS
	This script performs the installation or uninstallation of an application(s).
	# LICENSE #
	PowerShell App Deployment Toolkit - Provides a set of functions to perform common application deployment tasks on Windows. 
	Copyright (C) 2017 - Sean Lillis, Dan Cunningham, Muhammad Mashwani, Aman Motazedian.
	This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 
	You should have received a copy of the GNU Lesser General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
.DESCRIPTION
	The script is provided as a template to perform an install or uninstall of an application(s).
	The script either performs an "Install" deployment type or an "Uninstall" deployment type.
	The install deployment type is broken down into 3 main sections/phases: Pre-Install, Install, and Post-Install.
	The script dot-sources the AppDeployToolkitMain.ps1 script which contains the logic and functions required to install or uninstall an application.
.PARAMETER DeploymentType
	The type of deployment to perform. Default is: Install.
.PARAMETER DeployMode
	Specifies whether the installation should be run in Interactive, Silent, or NonInteractive mode. Default is: Interactive. Options: Interactive = Shows dialogs, Silent = No dialogs, NonInteractive = Very silent, i.e. no blocking apps. NonInteractive mode is automatically set if it is detected that the process is not user interactive.
.PARAMETER AllowRebootPassThru
	Allows the 3010 return code (requires restart) to be passed back to the parent process (e.g. SCCM) if detected from an installation. If 3010 is passed back to SCCM, a reboot prompt will be triggered.
.PARAMETER TerminalServerMode
	Changes to "user install mode" and back to "user execute mode" for installing/uninstalling applications for Remote Destkop Session Hosts/Citrix servers.
.PARAMETER DisableLogging
	Disables logging to file for the script. Default is: $false.
.EXAMPLE
    powershell.exe -Command "& { & '.\Deploy-Application.ps1' -DeployMode 'Silent'; Exit $LastExitCode }"
.EXAMPLE
    powershell.exe -Command "& { & '.\Deploy-Application.ps1' -AllowRebootPassThru; Exit $LastExitCode }"
.EXAMPLE
    powershell.exe -Command "& { & '.\Deploy-Application.ps1' -DeploymentType 'Uninstall'; Exit $LastExitCode }"
.EXAMPLE
    Deploy-Application.exe -DeploymentType "Install" -DeployMode "Silent"
.NOTES
	Toolkit Exit Code Ranges:
	60000 - 68999: Reserved for built-in exit codes in Deploy-Application.ps1, Deploy-Application.exe, and AppDeployToolkitMain.ps1
	69000 - 69999: Recommended for user customized exit codes in Deploy-Application.ps1
	70000 - 79999: Recommended for user customized exit codes in AppDeployToolkitExtensions.ps1
.LINK 
	http://psappdeploytoolkit.com
#>
[CmdletBinding()]
Param (
	[Parameter(Mandatory=$false)]
	[ValidateSet('Install','Uninstall')]
	[string]$DeploymentType = 'Install',
	[Parameter(Mandatory=$false)]
	[ValidateSet('Interactive','Silent','NonInteractive')]
	[string]$DeployMode = 'Interactive',
	[Parameter(Mandatory=$false)]
	[switch]$AllowRebootPassThru = $false,
	[Parameter(Mandatory=$false)]
	[switch]$TerminalServerMode = $false,
	[Parameter(Mandatory=$false)]
	[switch]$DisableLogging = $false
)

Try {
	## Set the script execution policy for this process
	Try { Set-ExecutionPolicy -ExecutionPolicy 'ByPass' -Scope 'Process' -Force -ErrorAction 'Stop' } Catch {}
	
	##*===============================================
	##* VARIABLE DECLARATION
	##*===============================================
	## Variables: Application
	[string]$appVendor = 'MyCompany'
	[string]$appName = 'MyNewApplication'
	[string]$appVersion = '1.00.0.2'
	[string]$appArch = 'x86'
	[string]$appLang = 'EN'
	[string]$appRevision = '01'
	[string]$appScriptVersion = '1.1.0'
	[string]$appScriptDate = '02/11/2018'
	[string]$appScriptAuthor = 'Me Me'
	[string]$appInstall = 'false'
	##*===============================================
	## Variables: Install Titles (Only set here to override defaults set by the toolkit)
	[string]$installName = ''
	[string]$installTitle = ''
	
	##* Do not modify section below
	#region DoNotModify
	
	## Variables: Exit Code
	[int32]$mainExitCode = 0
	
	## Variables: Script
	[string]$deployAppScriptFriendlyName = 'Deploy Application'
	[version]$deployAppScriptVersion = [version]'3.7.0'
	[string]$deployAppScriptDate = '02/13/2018'
	[hashtable]$deployAppScriptParameters = $psBoundParameters
	
	## Variables: Environment
	If (Test-Path -LiteralPath 'variable:HostInvocation') { $InvocationInfo = $HostInvocation } Else { $InvocationInfo = $MyInvocation }
	[string]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent
	
	## Dot source the required App Deploy Toolkit Functions
	Try {
		[string]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
		If (-not (Test-Path -LiteralPath $moduleAppDeployToolkitMain -PathType 'Leaf')) { Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]." }
		If ($DisableLogging) { . $moduleAppDeployToolkitMain -DisableLogging } Else { . $moduleAppDeployToolkitMain }
	}
	Catch {
		If ($mainExitCode -eq 0){ [int32]$mainExitCode = 60008 }
		Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
		## Exit the script, returning the exit code to SCCM
		If (Test-Path -LiteralPath 'variable:HostInvocation') { $script:ExitCode = $mainExitCode; Exit } Else { Exit $mainExitCode }
	}
	
	#endregion
	##* Do not modify section above
	##*===============================================
	##* END VARIABLE DECLARATION
	##*===============================================
		
	If ($deploymentType -ine 'Uninstall') {
		##*===============================================
		##* PRE-INSTALLATION
		##*===============================================
		[string]$installPhase = 'Pre-Installation'

		## Detect if applications are already installed
		$appInfo = Get-InstalledApplication -Name 'MyNewApplication' -Exact
		[Version]$appInfoVer = $appInfo.DisplayVersion

		If ($appInfoVer -lt [Version]$appVersion -or $appInfoVer -eq $null){
			$appInstall = 'True'
			$logMsg = $appName + " Install variable set to TRUE"
			Write-Log -Message $logMsg -Severity 1 -Source $deployAppScriptFriendlyName
		}
		If ($appInstall -eq 'False'){
			$logMsg = "Application Installation variables set to FALSE"
			Write-Log -Message $logMsg -Severity 1 -Source $deployAppScriptFriendlyName
			Exit-Script -ExitCode 0
		}

		## Display warning to save work
		$PromptMessage1 = "PLEASE SAVE YOUR WORK BEFORE PROCEEDING!!"
		$a=(Show-InstallationPrompt -Message $PromptMessage1 -Icon Information -ButtonLeftText 'Not Now.' -ButtonRightText 'Continue.')
		if ($a -eq "Not Now.") {Exit-Script -ExitCode 60012}
		
		## Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
		Show-InstallationWelcome -CloseApps 'winword' -AllowDefer -DeferTimes 3 -CheckDiskSpace -BlockExecution -PromptToSave $true -MinimizeWindows $false
		
		## Show Progress Message (with the default message)
		Show-InstallationProgress
		
		## <Perform Pre-Installation tasks here>
		Remove-MSIApplications -Name 'MyOldApplication' -Exact
		
		##*===============================================
		##* INSTALLATION 
		##*===============================================
		[string]$installPhase = 'Installation'
		
		## Handle Zero-Config MSI Installations
#		If ($useDefaultMsi) {
#			[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
#			Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) { $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ } }
#		}
		
		## <Perform Installation tasks here>
		Execute-MSI -Action 'Install' -Path 'MyNewApp.msi'
		
		##*===============================================
		##* POST-INSTALLATION
		##*===============================================
		[string]$installPhase = 'Post-Installation'
		
		## <Perform Post-Installation tasks here>
		
		## Display a message at the end of the install
		#If (-not $useDefaultMsi) { Show-InstallationPrompt -Message 'The installation has completed successfully.' -ButtonRightText 'OK' -Icon Information -NoWait }
		
	}
	ElseIf ($deploymentType -ieq 'Uninstall')
	{
		##*===============================================
		##* PRE-UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Pre-Uninstallation'
		
		## Show Welcome Message, close Internet Explorer with a 60 second countdown before automatically closing
		Show-InstallationWelcome -CloseApps 'winword' -BlockExecution -PromptToSave -MinimizeWindows $false
		
		## Show Progress Message (with the default message)
		Show-InstallationProgress
		
		## <Perform Pre-Uninstallation tasks here>
		
		
		##*===============================================
		##* UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Uninstallation'
		
		## Handle Zero-Config MSI Uninstallations
#		If ($useDefaultMsi) {
#			[hashtable]$ExecuteDefaultMSISplat =  @{ Action = 'Uninstall'; Path = $defaultMsiFile }; If ($defaultMstFile) { $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile) }
#			Execute-MSI @ExecuteDefaultMSISplat
#		}
		
		# <Perform Uninstallation tasks here>
		Remove-MSIApplications -Name 'MyNewApplication' -Exact
		
		##*===============================================
		##* POST-UNINSTALLATION
		##*===============================================
		[string]$installPhase = 'Post-Uninstallation'
		
		## <Perform Post-Uninstallation tasks here>
		
		
	}
	
	##*===============================================
	##* END SCRIPT BODY
	##*===============================================
	
	## Call the Exit-Script function to perform final cleanup operations
	Exit-Script -ExitCode $mainExitCode
}
Catch {
	[int32]$mainExitCode = 60001
	[string]$mainErrorMessage = "$(Resolve-Error)"
	Write-Log -Message $mainErrorMessage -Severity 3 -Source $deployAppScriptFriendlyName
	Show-DialogBox -Text $mainErrorMessage -Icon 'Stop'
	Exit-Script -ExitCode $mainExitCode
}

Have you tested psexec alone ? I.e. open a dos prompt as admin and type :
psexec -i -s cmd

Yeah, PsExec works fine, it just can’t find Deploy-Application.exe which is in the same source location as PsExec.exe without referencing the full path to Deploy-Application.exe.

For example; this works:

"PsExec.exe" -s - i -accepteula "C:\Temp\MyApp\Deploy-Application.exe"

I’ll just stick with my VBScript wrapper for now.

Any reason you aren’t using serviceui.exe to launch them?

I’ve not used ServiceUI before. I might give it a try. Thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.