This script works with MECM with these settings: Install for system, whether or not user logged in, maximized (for testing) and box checked: Allow users to interact - it returns 0 as expected
# Check registry value
$behavior = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\LCC\DEVICE' | Select-Object -ExpandProperty 'Behavior'
# Write-Host $behavior
# Run setup.exe and capture its exit code
If ($behavior -eq "Staff" -or $behavior -eq "Student" -or $behavior -eq "Podium") {
$setupProcess = Start-Process -FilePath ".\OES Client\setup.exe" -PassThru -Wait
$setupExitCode = $setupProcess.ExitCode
}
else {
Write-Host "Behavior value out of bounds or doesn't exist"
exit 1
}
# Check if setup.exe completed without error or specific exit codes
if ($setupExitCode -eq 0 -or $setupExitCode -eq 1707 -or $setupExitCode -eq 3010) {
$BatchFileExitCode = 0
# Check behavior value
switch ($behavior) {
"Staff" {
# Run NovellClient2Settings_Staff.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Staff.bat" -PassThru -Wait
}
"Student" {
# Run NovellClient2Settings_LAB.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_LAB.bat" -PassThru -Wait
}
"Podium" {
# Run NovellClient2Settings_Podium.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Podium.bat" -PassThru -Wait
}
}
# Wait for the batch file to complete and capture its exit code
$batchProcess.WaitForExit()
$BatchFileExitCode = $batchProcess.ExitCode
# Check if batch file completed without error
Write-Host "Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
# Create directory and copy files
$destination = "C:\ProgramData\Novell\Client\"
New-Item -ItemType Directory -Path $destination -Force
Copy-Item -Path ".\Graphics\*" -Destination $destination -Force
}
else {
Write-Host "Error: Batch file execution failed."
}
}
else {
Write-Host "Error: setup.exe execution failed with exit code $setupExitCode."
}
# Return the exit code of setup.exe or batch file to the calling application
Write-Host "Setup Exit Code: $setupExitCode, Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
exit $setupExitCode
}
else {
exit $BatchFileExitCode
}
And this script returns 0 for the setupExitCode and 0 for the batchExitCode and as long as I run it as system with psexec, it works fine and returns 3010 as expected. If I run it with MECM, it returns 1 (or I should say MECM receives exit code 1) even though setupExitCode is 0 and the batchExitCode is 0. The script is the same except for the last if statement that changes the setupExitCode.
(Note the installer doesn't return 3010 when it needs a reboot and it always needs a reboot after installing so I change the exit code to 3010 when the installer returns 0... but for some unfathomable reason this doesn't work.):
# Check registry value
$behavior = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\LCC\DEVICE' | Select-Object -ExpandProperty 'Behavior'
# Write-Host $behavior
# Run setup.exe and capture its exit code
If ($behavior -eq "Staff" -or $behavior -eq "Student" -or $behavior -eq "Podium") {
$setupProcess = Start-Process -FilePath ".\OES Client\setup.exe" -PassThru -Wait
$setupExitCode = $setupProcess.ExitCode
}
else {
Write-Host "Behavior value out of bounds or doesn't exist"
pause
exit 1
}
# Check if setup.exe completed without error or specific exit codes
if ($setupExitCode -eq 0 -or $setupExitCode -eq 1707 -or $setupExitCode -eq 3010) {
$BatchFileExitCode = 0
# Check behavior value
switch ($behavior) {
"Staff" {
# Run NovellClient2Settings_Staff.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Staff.bat" -PassThru -Wait
}
"Student" {
# Run NovellClient2Settings_LAB.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_LAB.bat" -PassThru -Wait
}
"Podium" {
# Run NovellClient2Settings_Podium.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Podium.bat" -PassThru -Wait
}
}
# Wait for the batch file to complete and capture its exit code
$batchProcess.WaitForExit()
$BatchFileExitCode = $batchProcess.ExitCode
# Check if batch file completed without error
Write-Host "Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
# Create directory and copy files
$destination = "C:\ProgramData\Novell\Client\"
New-Item -ItemType Directory -Path $destination -Force
Copy-Item -Path ".\Graphics\*" -Destination $destination -Force
}
else {
Write-Host "Error: Batch file execution failed."
}
}
else {
Write-Host "Error: setup.exe execution failed with exit code $setupExitCode."
}
# Return the exit code of setup.exe or batch file to the calling application
Write-Host "Setup Exit Code: $setupExitCode, Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
if ($setupExitCode -eq 0) {
$setupExitCode = 3010
}
exit $setupExitCode
}
else {
exit $BatchFileExitCode
}
I have given up on solving it... there is no rhyme or reason here. My solution at this point is to just change the behavior of the exit code 0 to soft reboot and be done with it... is there smoke coming from your ears yet???
# Check registry value
$behavior = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\LCC\DEVICE' | Select-Object -ExpandProperty 'Behavior'
# Write-Host $behavior
# Run setup.exe and capture its exit code
If ($behavior -eq "Staff" -or $behavior -eq "Student" -or $behavior -eq "Podium") {
$setupProcess = Start-Process -FilePath ".\OES Client\setup.exe" -PassThru -Wait
$setupExitCode = $setupProcess.ExitCode
}
else {
Write-Host "Behavior value out of bounds or doesn't exist"
exit 1
}
# Check if setup.exe completed without error or specific exit codes
if ($setupExitCode -eq 0 -or $setupExitCode -eq 1707 -or $setupExitCode -eq 3010) {
$BatchFileExitCode = 0
# Check behavior value
switch ($behavior) {
"Staff" {
# Run NovellClient2Settings_Staff.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Staff.bat" -PassThru -Wait
}
"Student" {
# Run NovellClient2Settings_LAB.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_LAB.bat" -PassThru -Wait
}
"Podium" {
# Run NovellClient2Settings_Podium.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Podium.bat" -PassThru -Wait
}
}
# Wait for the batch file to complete and capture its exit code
$batchProcess.WaitForExit()
$BatchFileExitCode = $batchProcess.ExitCode
# Check if batch file completed without error
Write-Host "Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
# Create directory and copy files
$destination = "C:\ProgramData\Novell\Client\"
New-Item -ItemType Directory -Path $destination -Force
Copy-Item -Path ".\Graphics\*" -Destination $destination -Force
}
else {
Write-Host "Error: Batch file execution failed."
}
}
else {
Write-Host "Error: setup.exe execution failed with exit code $setupExitCode."
}
# Return the exit code of setup.exe or batch file to the calling application
Write-Host "Setup Exit Code: $setupExitCode, Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
exit $setupExitCode
}
else {
exit $BatchFileExitCode
}
And this script returns 0 for the setupExitCode and 0 for the batchExitCode and as long as I run it as system with psexec, it works fine and returns 3010 as expected. If I run it with MECM, it returns 1 (or I should say MECM receives exit code 1) even though setupExitCode is 0 and the batchExitCode is 0. The script is the same except for the last if statement that changes the setupExitCode.
(Note the installer doesn't return 3010 when it needs a reboot and it always needs a reboot after installing so I change the exit code to 3010 when the installer returns 0... but for some unfathomable reason this doesn't work.):
# Check registry value
$behavior = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\LCC\DEVICE' | Select-Object -ExpandProperty 'Behavior'
# Write-Host $behavior
# Run setup.exe and capture its exit code
If ($behavior -eq "Staff" -or $behavior -eq "Student" -or $behavior -eq "Podium") {
$setupProcess = Start-Process -FilePath ".\OES Client\setup.exe" -PassThru -Wait
$setupExitCode = $setupProcess.ExitCode
}
else {
Write-Host "Behavior value out of bounds or doesn't exist"
pause
exit 1
}
# Check if setup.exe completed without error or specific exit codes
if ($setupExitCode -eq 0 -or $setupExitCode -eq 1707 -or $setupExitCode -eq 3010) {
$BatchFileExitCode = 0
# Check behavior value
switch ($behavior) {
"Staff" {
# Run NovellClient2Settings_Staff.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Staff.bat" -PassThru -Wait
}
"Student" {
# Run NovellClient2Settings_LAB.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_LAB.bat" -PassThru -Wait
}
"Podium" {
# Run NovellClient2Settings_Podium.bat
$batchProcess = Start-Process -FilePath ".\Config\NovellClient2Settings_Podium.bat" -PassThru -Wait
}
}
# Wait for the batch file to complete and capture its exit code
$batchProcess.WaitForExit()
$BatchFileExitCode = $batchProcess.ExitCode
# Check if batch file completed without error
Write-Host "Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
# Create directory and copy files
$destination = "C:\ProgramData\Novell\Client\"
New-Item -ItemType Directory -Path $destination -Force
Copy-Item -Path ".\Graphics\*" -Destination $destination -Force
}
else {
Write-Host "Error: Batch file execution failed."
}
}
else {
Write-Host "Error: setup.exe execution failed with exit code $setupExitCode."
}
# Return the exit code of setup.exe or batch file to the calling application
Write-Host "Setup Exit Code: $setupExitCode, Batch Exit Code: $BatchFileExitCode"
if ($BatchFileExitCode -eq 0) {
if ($setupExitCode -eq 0) {
$setupExitCode = 3010
}
exit $setupExitCode
}
else {
exit $BatchFileExitCode
}
I have given up on solving it... there is no rhyme or reason here. My solution at this point is to just change the behavior of the exit code 0 to soft reboot and be done with it... is there smoke coming from your ears yet???