Launch an unparented process from PowerShell -


by default, when launch process powershell, attached parent (the shell). if kill process tree, these processes die. launch process peer shell; aka. when kill powershell tree, don't want die.

$spotifyprocess = start spotify.exe -passthru  $spotifyparentid = (gwmi win32_process -filter "processid='$($spotifyprocess.id)'").parentprocessid $shellid = [system.diagnostics.process]::getcurrentprocess().id  if ($spotifyparentid -eq $shellid) {     throw 'not want!!' } 

a "classic" trick, due simple nature of process tree in windows (just backwards linked list each process' ancestor), open separate process in turn launches new "independent" process.

in powershell.exe super easy:

powershell.exe -command 'start-process notepad.exe' 

the "inner" powershell.exe instance launches notepad.exe, , exits immediately, leaving notepad.exe orphaned


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -