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
Post a Comment