0

If I double click a shortcut to a folder and open that folder, then I double click the same shortcut again, Windows doesn't open a second instance of the folder, it activates (or maximizes) the folder if it's already open, which is the behavior I am trying to replicate on the command line.

I can run this in a bat file: explorer "MyFolder"

That opens the "MyFolder" folder that's beside the bat file, but if I run the bat file again with "MyFolder" already open, it opens another instance of the folder.

explorer.exe barely has any switches to it at all, so I wondered if there is some other workaround or secret switch that's undocumented, so it wouldn't matter if the bat file was run multiple times, only one instance of "MyFolder" would open?

Maybe there's a small command line program that handles this problem but I don't know of anything, hence asking here.

Cheers in advance.

EDIT: After some fiddling around, this works but if the folder is already maximized, it minimizes it. It does work to only open one instance though... start "" "MyFolder"

I guess this could be usable but it's inconvenient having the folder minimize itself if it's already open and maximized.

I could create a shortcut to the folder and run that on the command line with the properties set to "Run Maximized" but I don't want it filling the screen, which "Run Maximized" would do.

6
  • Why batch? powerShell is the native scripting language of Windows now. There you can access the Shell.Applcation Com object and use the Open() method which replicates the UI behavior. Mar 25, 2022 at 6:50
  • Indeed Powershell is far better, but I'd still need to run any Powershell command via a batch file - because the .bat file is hard-coded into another exe that runs it. I managed to solve it (see EDIT 2).
    – bat_cmd
    Mar 25, 2022 at 6:55
  • Please don't edit your question to include the answer, answer your own question. Please read Can I answer my own question?
    – DavidPostill
    Mar 25, 2022 at 8:32
  • No because you've deleted the solution out of the question. If you can put the question back the way it was again (containing the solution) I will edit the question, copy the relevant part, then delete it, then save it, then add the copied part as an answer. I'm not typing it out again when it was already there. If you can't restore it then it's gone forever, thanks for that! Any future readers of this question will simply have to struggle to find the answer like I had to - I'm certainly not adding it again when I have already added it. What exactly was the point of removing the solution?
    – bat_cmd
    Mar 25, 2022 at 10:46
  • @bat_cmd you can find any old revisions to your question in the revision history that is available in the "edited x hours ago" link: superuser.com/posts/1712705/revisions you can copy your answer from there. Solutions should not be in the question, they should be posted as answers.
    – Mokubai
    Mar 25, 2022 at 11:10

1 Answer 1

0

I have solved it by creating a shortcut to the folder with Target:

%COMSPEC% /C start "" "MyFolder"

The shortcut can then be executed by:

start "" "MyFolder_Shortcut"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .