I've followed all the examples in these threads but something has changed in the latest update it seems.
Close Explorer window by varying ID or filename
Closing All Explorer Windows in PowerShell
My windows version is: Version: 1909 BuildNumber: 18363
I'm stuck with trying to close an explorer window using PowerShell with the following code:
$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() }
If you open up C:\Program Files
you'll see that the methods described in the code work but the Quit
method doesn't.