嘿,我没有得到解决方案,
但也许我的方法是解决您的方法。
我玩了一下 .net 函数并了解了过程。
进程直接没了,调用资源管理器后...
所以基函数是
[System.Diagnostics.Process]::Start("explorer.exe", "C:\")
什么返回进程:
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id SI ProcessName
------- ------ ----- ----- ----- ------ -- -- -----------
4 2 392 1140 10 0,00 6328 1 explorer
其中还有一些功能,例如:
[System.Diagnostics.Process]::Start("explorer.exe", "C:\").WaitForExit()
但是什么也没发生 :(
如果将结果放入变量中,可以发现函数和属性:
$tmp = [System.Diagnostics.Process]::Start("explorer.exe", "C:\")
键入 $tmp。并在 ISE 中点击 Strg + Space
然后我通过 get-process cmd 处理了这个过程
$process = get-process -Id ([System.Diagnostics.Process]::Start("explorer.exe", "C:\")).Id
这导致我的过程如下:
> $process
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id SI ProcessName
------- ------ ----- ----- ----- ------ -- -- -----------
0 1 384 120 6 8396 1 explorer
但同样的:这个过程立即消失了:(
我玩了一圈,得到了这个解决方案:
$path = "C:\temp\test"
$split = $path.split("\\")
$mainWindowTitle = $split[$split.Length - 1]
$tmp = [System.Diagnostics.Process]::Start("explorer.exe", $path)
sleep -Seconds 2
Get-Process | ? ProcessName -eq explorer | select * | ? MainWindowTitle -eq $mainWindowTitle | select Id
使用此代码,我得到了您正在寻找的流程。
让我给你解释一下。
首先我需要路径,以及其中的最后一个子目录。每个资源管理器进程都有一个 mainWindowTitle,其值为打开的目录的名称。
所以我启动了带有特定路径的资源管理器,并拆分了最后一个子目录。您需要睡眠 1 或 2 秒,因为进程需要一段时间才能进入进程列表。
然后我搜索了每个资源管理器,其中 windowMainTitle 等于最后一个子目录。
所以现在你得到了 processId,它允许你创建一个 while 循环,其中有一个 sleep,你可以在其中检查进程是否仍然存在。
唯一的问题是,窗口不能打开两次或同名目录。
但也许您可以使用此代码。随便玩玩,看看你能想出什么。
编辑:
这段代码对我有用:)
$path = "C:\temp\test"
$split = $path.split("\\")
$mainWindowTitle = $split[$split.Length - 1]
$tmp = [System.Diagnostics.Process]::Start("explorer.exe", $path)
sleep -Seconds 2
$processId = (Get-Process | ? ProcessName -eq explorer | select * | ? MainWindowTitle -eq $mainWindowTitle | select Id).Id
while((get-process -Id $processId ).Length -gt 0){
sleep -Seconds 1
$processId = (Get-Process | ? ProcessName -eq explorer | select * | ? MainWindowTitle -eq $mainWindowTitle | select Id).Id
}
# All code after will be executed after window was closed
write-host "Window Closed"
Greetz Eldo.Ob