Close File Explorer Window

Page 2 of 2 FirstFirst 12

  1. Posts : 841
    Windows 10 Pro 21H2
    Thread Starter
       #11

    KeithM said:
    The best of both our code versions, a one liner!
    Code:
    (New-Object -ComObject Shell.Application).Windows() | %{$_.quit()}
    Keith
    Excellent, that works....
      My Computer


  2. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #12

    KeithM said:
    The best of both our code versions, a one liner!
    Code:
    (New-Object -ComObject Shell.Application).Windows() | %{$_.quit()}
    Keith,

    That also closes IE. [Added later - Keith has posted a fix below]

    Denis
    Last edited by Try3; 06 Apr 2019 at 11:56.
      My Computer


  3. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #13

    rdwray said:
    I did not get yours' to work, but with your suggestion, I did find this one:
    Code:
    $a = (New-Object -comObject Shell.Application).Windows() |  ? { $_.FullName -ne $null} |
     ? { $_.FullName.toLower().Endswith('\explorer.exe') } 
    
     $a | % {  $_.Quit() }
    That one closes File explorer windows [without the side effect of closing IE].

    Thanks,

    Denis
      My Computer


  4. Posts : 989
    Microsoft Windows 10 Home
       #14

    True. I remember that from XP days. Didn't mention because so few people use IE anymore. But, if you want to limit it to File Explorer windows, use:
    Code:
    (New-Object -ComObject Shell.Application).Windows() | ?{$_.name -match 'file'} | %{$_.quit()}
    Keith
      My Computer


  5. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #15

    Keith,

    Thanks. Now filed away in my PS studies folders.

    Denis
      My Computer


  6. Posts : 17,838
    Windows 10
       #16

    Wouldn't it be as easy, or easier, to Ctrl+Shift+right click Taskbar and Exit Explorer?
      My Computer


  7. Posts : 16,910
    Windows 10 Home x64 Version 22H2 Build 19045.4170
       #17

    Edwin said:
    Wouldn't it be as easy, or easier, to Ctrl+Shift+right click Taskbar and Exit Explorer?
    Edwin,

    The OP needs to do it within a script.

    All the best,
    Denis
      My Computer


  8. Posts : 989
    Microsoft Windows 10 Home
       #18

    Edwin said:
    Wouldn't it be as easy, or easier, to Ctrl+Shift+right click Taskbar and Exit Explorer?
    Also, that kills the shell process, which the OP wanted to avoid.

    Keith
      My Computer


  9. Posts : 68,836
    64-bit Windows 11 Pro for Workstations
       #19

    Hello @rdwray,

    If you are wanting a way to close all explorer instances and restart the explorer process, then you might see if the context menu added by the tutorial below may work for you for this.

    Restart Explorer Context Menu - Add in Windows 10
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 06:36.
Find Us




Windows 10 Forums