I have created a simple GUI app with buttons and each button click will give an exit code. The script is working fine and I am getting the exit code when i run the script. However I am not able to retrieve the exit code in powershell using $LASTEXITCODE variable. Its always empty or sometimes 0.
For e.g. the compiled EXE is called TEST.EXE and if I call it inside my powershell script as mentioned below, then the $lastexitcode is always empty or 0. But i know the exit code is coming as i can see it
Code: Select all
Start-Process test.exe
$lastexitcode
Code: Select all
PS C:\temp> .\test.exe
22
PS C:\temp> $lastexitcode
0
PS C:\temp> .\test.exe
11
PS C:\temp> $lastexitcode
0
0
I have the following in the "Startup.pss" file. I commented the default option as it was giving only 0
Code: Select all
#$script:ExitCode = 0 #Set the exit code for the Packager
$script:lastexitcode
Code: Select all
$buttonYes_Click = {
$script:lastexitcode = 22
return $script:lastexitcode
}
$buttonNo_Click={
$script:lastexitcode = 11
return $script:lastexitcode
}