5

我正在编写以下代码以使用 PowerShell 关闭所有资源管理器窗口:

(New-Object -comObject Shell.Application).Windows() |
 ? { $_.FullName -ne $null} |
 ? { $_.FullName.toLower().Endswith('\explorer.exe') } | % { $_.Quit() }

但它不会关闭所有打开的窗口。相反,它只关闭RoundDown(N/2)+1窗口,并让RoundUp(N/2)-1窗口保持打开状态。

有人能帮忙吗?

4

3 回答 3

14

我认为管道中出现了问题。此代码有效:

$a = (New-Object -comObject Shell.Application).Windows() |
 ? { $_.FullName -ne $null} |
 ? { $_.FullName.toLower().Endswith('\explorer.exe') } 

 $a | % {  $_.Quit() }
于 2013-07-19T20:12:40.810 回答
2
Stop-Process -Name explorer

杀死所有相关进程

于 2020-07-01T15:07:27.480 回答
1

根据@ste 的评论,接受的答案可能在 Windows 更新后停止工作。

我已经在 Powershell 中用类似的东西解决了它。

请注意,因为我假设任何带有窗口标题的资源管理器进程都是文件夹。情况可能并非总是如此(例如,如果复制文件)

get-process | ?{ $_.ProcessName -eq 'Explorer' } | ?{ "" -ne $_.MainWindowTitle } | Stop-Process
于 2020-10-15T12:38:09.993 回答