2

So, I'm trying to use a batch file to open various instances of Windows File explorer in various locations on my desktop instead of them all starting right on top of each other, which is annoying. I've had no luck Googling this, so what can I incorporate into my batch script that will force each window to open in a specific location and at a certain size on my desktop? I'm not afraid to use plugins or 3rd party solutions.

This is an example of the script I have so far, which just opens them all on top of each other:

@echo off
start explorer "M:\2) Mathematical Innovations"
start explorer "This PC\3) Pictures"
start explorer "D:\5) Projects\Ae"

What should I do?

  • Can't be done using batch alone. There is [no switch for that](https://support.microsoft.com/en-us/kb/130510). You might try to create a program that opens a directory and moves the window by sending window messages to it. – GolezTrol Jul 19 '15 at 17:48
  • Unfortunately, I have no idea how to do that. My experience is too limited and I basically have to edit examples that already work to match my needs. – Laughable Junnyzup Jul 19 '15 at 17:59
  • @LaughableJunnyzup If my answer below was helpful, please consider marking it as accepted. [See this page](http://meta.stackexchange.com/questions/5234/) for an explanation of why this is important. – rojo Jul 20 '15 at 12:39

2 Answers2

4

Setting window X, Y, W, and H with specific coordinates and dimensions requires programmatic access to SetWindowPos, which would require you to compile and link a C# program or similar.

As an alternative, you could launch all your Explorer windows, then call the WSH Shell.Application COM object's TileHorizontally() or TileVertically() method to let Windows figure out how to tile them. You can do it with a PowerShell one-liner within your batch script like this:

@echo off
setlocal

start explorer "M:\2) Mathematical Innovations"
start explorer "This PC\3) Pictures"
start explorer "D:\5) Projects\Ae"

rem // pause for 3 seconds to allow the windows to appear
timeout /t 3 >NUL

powershell "(new-object -COM 'Shell.Application').TileVertically()"
Community
  • 1
  • 1
rojo
  • 24,000
  • 5
  • 55
  • 101
0

Great script, only comment is the batch file window was getting included so first just changed the shortcut to run minimized. But then found the below that is even better.

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:\Batch Files\syncfiles.bat" & Chr(34), 0
Set WshShell = Nothing
sorak
  • 2,607
  • 2
  • 16
  • 24