简体   繁体   English

如何获取从Powershell启动的资源管理器的进程ID

[英]How to get the process id of Explorer launched from Powershell

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. 我从Powershell启动了“ Explorer.exe”,并希望获取资源管理器窗口的进程ID,以便不会在其他资源管理器窗口上误操作。

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. 代码:Start-Process“ Explorer.exe” -PassThru结果:我可以看到进程ID,但是与UISpy或任务管理器中窗口的实际进程ID不同。 Seems explorer.exe start another process (B) can exit itself and finally we see the process (B). 似乎explorer.exe启动另一个进程(B)可以退出自身,最后我们看到了进程(B)。 And the process I got is the exited process. 我得到的过程就是退出的过程。 Question: How can I get the real process id (B)? 问题:如何获取真实的进程ID(B)?

Explorer.exe will momentarily start a brand new process, but that process will die quickly, handing off its state to an existing explorer process. Explorer.exe将立即启动一个全新的过程,但是该过程将很快终止,并将其状态移交给现有的资源管理器过程。 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] 我认为这与注册表项HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced [SeparateProcess]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM