How to get the process id of Explorer launched from Powershell

巧了我就是萌 提交于 2019-12-12 09:55:43

问题


I started "Explorer.exe" from Powershell and want to get the process id of the explorer window so that I would not mis-operate on other explorer windows.

Code: Start-Process "Explorer.exe" -PassThru Result: I can see the process id but it's different with the real process id of the window in UISpy or in task manager. Seems explorer.exe start another process (B) can exit itself and finally we see the process (B). And the process I got is the exited process. Question: How can I get the real process id (B)?


回答1:


Explorer.exe will momentarily start a brand new process, but that process will die quickly, handing off its state to an existing explorer process. In general, it will not persist and add to a growing collection of processes, as most programs would.

See this in action:

"Old explorer.exe instances"
Get-Process explorer

Start-Process explorer.exe
sleep 1  # wait for this one to die

"New explorer.exe instances"
Get-Process explorer

You will see that it's the same set of explorer instances. I think this is related to the reg key HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced [SeparateProcess]



来源:https://stackoverflow.com/questions/12084221/how-to-get-the-process-id-of-explorer-launched-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!