Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start and stop processes in PowerShell?

This should work fine in PowerShell older than 3. I need to run two processes: wuapp.exe and desk.cpl with ScreenSaver's tab. The problem I have is that once I start wuapp.exe the process name shows up in Task Manager as explorer.exe - the current code works for wuapp.exe but not on every machine. The other thing is when I kill rundll32 other apps will close also. What do you suggest?

$wshell = New-Object -ComObject Wscript.Shell
Start-Process  wuapp.exe
(New-Object -comObject Shell.Application).Windows() | foreach-object {$_.quit()}
Start-Process rundll32 desk.cpl,InstallScreenSaver
Stop-Process -ProcessName rundll32* -Force
like image 460
ppiotrek Avatar asked Feb 21 '26 10:02

ppiotrek


1 Answers

I'm not entirely sure what you mean by wuapp.exe showing up as explorer.exe, but keeping track of the rundll32 process is fairly straightforward.

Use Start-Process with the PassThru parameter to have it return the process it creates:

$ScreenSaverCpl = Start-Process rundll32 desk.cpl,InstallScreenSaver -PassThru
# Call Stop-Process when no longer needed:
Stop-Process $ScreenSaverCpl
like image 116
Mathias R. Jessen Avatar answered Feb 23 '26 09:02

Mathias R. Jessen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!