I know how to already run an exe file, easy part. I also figured out how to run a command when powershell closes:
Register-EngineEvent PowerShell.Exiting –Action { 'Code' }
But I can't figure out how I would run a program with Powershell and then have it execute a command in Powershell when it closes, and then close Powershell itself.
$job = Start-Job { net start wuauserv }
Wait-Job $job
Receive-Job $job
Start-Process -FilePath "C:\Program Files (x86)\CpuCoreParking\CpuCoreParking3.exe" -Wait
Register-EngineEvent PowerShell.Exiting –Action {
$job = Start-Job { net stop wuauserv }
Wait-Job $job
Receive-Job $job
Start-Sleep -Seconds 2
}
This is my code so far, but it doesn't seem to stop the service on the end. Nothing happens, it just closes itself after I close the program. It does do something but ... not sure what.
Start-Processcmdlet has a-Waitparameter that may give you all that you need for this. have you tried it? [grin]