Don't use start-process. Call the .exe's directly and test the lastexitcode.
$runme = 'c:\windows\system32\whoami.exe'
$parm = '/user'
& $runme $parm
$LASTEXITCODE
$parm = '/bad-argument'
& $runme $parm
$LASTEXITCODE
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a PS to enable automatic updates. I have a variable to OfficeC2RClient.exe I have a variable for args, "/update user display level=true" then, Start-Process (both variables). This kicks off Office upgrades which is what we want. But since we don't know exactly when it completes (no notification this way), I want to Start-Process winward.exe The strange thing is, the very first thing that happens is Word launches, then the updates start, then Word runs again after. I can't figure out why Word runs as the very first step in this PS. cd HKLM:\ Set-ItemProperty -Path "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Office\16.0\common\OfficeUpdates" -Name EnableAutomaticUpdates -Value 1 -Force $UpdateEXE = "C:\Program Files\Common Files\microsoft shared\ClickToRun\OfficeC2RClient.exe" $UpdateArguements = "/update user displaylevel=true" Start-Process $UpdateEXE $UpdateArguements Start-Process winword.exe
Don't use start-process. Call the .exe's directly and test the lastexitcode.
$runme = 'c:\windows\system32\whoami.exe'
$parm = '/user'
& $runme $parm
$LASTEXITCODE
$parm = '/bad-argument'
& $runme $parm
$LASTEXITCODE
Hi,
There's no need to run word. To wait for a process and its descendants to complete you can use the -Wait parameter. If you want to get the exit time you can add the -PassThru parameter to generate outputs.
$updateprocess = Start-Process $UpdateEXE $UpdateArguements -Wait -PassThru
$updateprocess.ExitTime
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.