如何获取从 Powershell 启动的 Explorer 的进程 ID [英] How to get the process id of Explorer launched from Powershell

查看:84
本文介绍了如何获取从 Powershell 启动的 Explorer 的进程 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 Powershell 启动了Explorer.exe",想获取资源管理器窗口的进程 ID,以免在其他资源管理器窗口上误操作.

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.

代码:启动进程Explorer.exe"-PassThru结果:我可以看到进程 id,但它与 UISpy 或任务管理器中窗口的真实进程 id 不同.似乎 explorer.exe 启动另一个进程(B)可以自行退出,最后我们看到进程(B).我得到的进程是退出的进程.问题:我怎样才能得到真正的进程 id (B)?

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)?

推荐答案

Explorer.exe 将暂时启动一个全新的进程,但该进程将很快终止,将其状态移交给现有的资源管理器进程.一般来说,它不会像大多数程序那样持久存在并添加到不断增长的进程​​集合中.

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.

看看这个:

"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

您会看到这是一组相同的资源管理器实例.我认为这与注册表项 HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced [SeparateProcess]

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]

这篇关于如何获取从 Powershell 启动的 Explorer 的进程 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆