首页 > 解决方案 > .Quit() 方法无法在 Windows 版本 1909 中关闭 PowerShell 中的文件资源管理器窗口

问题描述

我已经遵循了这些线程中的所有示例,但似乎在最新更新中发生了一些变化。

通过改变 ID 或文件名关闭资源管理器窗口

在 PowerShell 中关闭所有资源管理器窗口

如何关闭所有窗口

我的windows版本是: Version: 1909 BuildNumber: 18363

我坚持尝试使用带有以下代码的 PowerShell 关闭资源管理器窗口:

$myFolder = "C:\Program Files"
$shell = New-Object -ComObject Shell.Application
$window = $shell.Windows() | Where-Object { $_.LocationURL -eq "$(([uri]"$myFolder").AbsoluteUri)" }
write-output ($window.LocationURL -eq $(([uri]"$myFolder").AbsoluteUri))
                                 # write-output $window.AbsoluteUri
                                 # write-output ($window.HWND)
                                 # write-output ($window.LocationURL)
                                 # Get-Member -InputObject $window.Parent()
Get-Member -InputObject $window  # prints out the methods associated with the window
$window.Refresh()                # this method works
$window.Quit()                   # this method doesn't
$window.GoBack()                 # this method works
$window.Parent().Quit()          # this doesn't
                                 # $window | ForEach-Object { $_.Quit() }

如果您打开,C:\Program Files您会看到代码中描述的方法有效,但Quit方法无效。

标签: powershell

解决方案


推荐阅读