none
Unable to close a specific explorer window using a batch file RRS feed

  • General discussion

  • I am trying to create a batch file to access a share location say \ \test and then to close the opened explorer window. I am able to open the share location window but facing hard time to close it. I tried to use the taskkill WINDOWTITLE command but that too is not working.
    I am using the below scripting.
    ================================
    @echo Off
    start \ \test
    Taskkill /f /FI "WINDOWTITLE eq test*"
    =================================
    The above script is opening the share location(\ \test) on an explorer window but not closing that window.
    I also tried Taskkill /f /IM explorer.exe, but that is completely closing my explorer.exe and then I have to add start explorer.exe to my batch file to again start the explorer, which I do not want.

    I also directly tried the command in CMD and got the below message.
    c:\windows\system32>Taskkill /f /FI "WINDOWTITLE eq test*"
    INFO: No tasks running with the specified criteria.

    How can I only close that particular opened explorer window(in which the \ \test shares are opened) only?

    • Edited by Ran_UserA Thursday, April 19, 2018 12:24 AM
    • Changed type Bill_Stewart Friday, July 27, 2018 4:30 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 4:31 PM This is not "scripts on demand"
    Thursday, April 19, 2018 12:22 AM

All replies

  • You are obviously using the wrong window title.


    \_(ツ)_/

    Thursday, April 19, 2018 1:35 AM
  • May be and that's for what I need help/suggestions with. So that I can achieve what I am looking for.

    Any suggestions from your end to correct this??

    Thursday, April 19, 2018 4:08 PM
  • The above link is more taking about a powershell scripts and not a CMD .bat file script. Is seems the O.S has the command line to open any window but not close it.

    Need help in creating cmd .bat script to achieve the goal. Any suggestions for that ?


    Thursday, April 19, 2018 7:55 PM
  • Run the script and see what you find.  It will explain why you cannot do this with a batch file.  Batch is obsolete for may reasons.  You should not be using it.


    \_(ツ)_/


    • Edited by jrv Thursday, April 19, 2018 7:57 PM
    Thursday, April 19, 2018 7:56 PM
  • So do you confirm that this will not be achievable using a Batch file. I have to use a powershell script instead at any cost?

    Thursday, April 19, 2018 8:02 PM
  • Yes.  Batch cannot get the PID of the process just started.  PowerShell can.  There is no window title when you launch explorer because explorer is always running and you are just showing a particular folder.

    Your issue is mostly because you don't know Windows and how it works.  "Explorer" is the desktop.  It is not an application like notepad.


    \_(ツ)_/

    Thursday, April 19, 2018 8:07 PM
  • I will still appreciate if anyone can help me with a cmd batch file script to achieve the same as me and my team is not comfortable with Powershell scripting.
    Thursday, April 19, 2018 8:08 PM
  • I will still appreciate if anyone can help me with a cmd batch file script to achieve the same as me and my team is not comfortable with Powershell scripting.

    It cannot be done with a batch file.

    \_(ツ)_/

    Thursday, April 19, 2018 8:16 PM
  • This is a great opportunity to get started learning PowerShell. Don't get left behind.

    -- Bill Stewart [Bill_Stewart]

    Thursday, April 19, 2018 8:31 PM