Align Windows via bat

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Peterequelle
Posts: 1
Joined: 17 Jun 2016 02:16

Align Windows via bat

#1 Post by Peterequelle » 17 Jun 2016 04:46

Hi,
I programmed a little bat file that opens two folders on the desktop. Is it possible to automatically align the folders on the screen ? Like dragging it on the side with the mouse or pressen Windows+Arrow Key ?

Code is:

explorer "D:\mypath"
IF exist F:\mypath explorer "F:\mypath"

Regards

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Align Windows via bat

#2 Post by sambul35 » 17 Jun 2016 10:59

Provided there're just 2 above windows open on the desktop, save required Align.vbs script to a file, and launch it from a batch:

Code: Select all

cscript "K:\Files\Align.vbs"

aGerman
Expert
Posts: 4689
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Align Windows via bat

#3 Post by aGerman » 17 Jun 2016 11:24

As sambul35 already insinuated you would need another language. Of course you could also write it in a hybrid script.

*.bat

Code: Select all

@if (@a)==(@b) @end /* Batch portion:

@echo off &setlocal

:: run this script as JScript code and pass the folders that should be opened and tiled vertically
cscript //nologo /e:jscript "%~fs0" "C:\Windows" "C:\Program Files"

exit /b


JScript portion: */

var objWShell = new ActiveXObject('Wscript.Shell');
var objShellApp = new ActiveXObject('Shell.Application');
var objFSO = new ActiveXObject('Scripting.FileSystemObject');

// minimize all open windows
objShellApp.MinimizeAll();

// iterate over the passed arguments
for (var i = 0; i < WScript.Arguments.Count(); ++i){
  // if the passed folder exists
  if (objFSO.FolderExists(WScript.Arguments.Item(i))){
    // suspend the execution of the script for a few milliseconds in order to make sure the former operation was triggered
    WScript.Sleep(150);
    // open the folder in a new explorer window
    objWShell.Run('explorer.exe /n,"' + WScript.Arguments.Item(i) + '"');
  }
}

// suspend the execution of the script for 2 seconds in order to give the windows a chance to open
WScript.Sleep(2000);

// tile all of the (not minimized) windows vertically
objShellApp.TileVertically();

Regards
aGerman

sambul35
Posts: 192
Joined: 18 Jan 2012 10:13

Re: Align Windows via bat

#4 Post by sambul35 » 17 Jun 2016 12:07

Will it tile only the Explorer windows, even if other program windows are open? My above suggestion can't do that. :wink: I'd rather use free WDE instead of a batch for this.

aGerman
Expert
Posts: 4689
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Align Windows via bat

#5 Post by aGerman » 17 Jun 2016 12:40

The TileVertically() method tiles all of the windows on the desktop. For that reason I minimize already opened windows (including the console window) before I open the new Explorer windows. Thus, only the Explorer windows are on the desktop...

Regards
aGerman

Post Reply