I want to open my batch file's console window in a specific location on the screen. I have searched in Google, but I did not find a solution for this. I need four small console windows, one in each corner of the screen.
-
1Maybe this [Set The Window Position of an application via command line](https://stackoverflow.com/questions/7977322/set-the-window-position-of-an-application-via-command-line) – Squashman Nov 01 '18 at 21:36
-
I cant find the solution, Please any help me, regarding this – VyTcdc Nov 01 '18 at 21:54
1 Answers
@echo off
setlocal
if /i "%~1" == "/4way" (
console4way "%~f0" %*
exit /b
)
echo Running %*
console4way
#pragma compile(Out, console4way.exe)
Global $aPid[4]
; Run ComSpec (usually set as CMD) with arguments for the 1st instance.
$aPid[0] = Run('"' & @ComSpec & '" /k ' & StringReplace($CMDLINERAW, '/4way', '', 1))
For $i1 = 1 To 3
$aPid[$i1] = Run('"' & @ComSpec & '"')
Next
; Give time for all windows to display.
Sleep(500)
; Get list of all console class windows.
$aWinList = WinList('[CLASS:ConsoleWindowClass]')
For $i1 = 1 To UBound($aWinList) -1
; Get current window handle from the list.
$hWindow = $aWinList[$i1][1]
; Get position and sizes of current window.
$aPos = WinGetPos($hWindow)
; Move windows if process id matches.
Switch WinGetProcess($hWindow)
Case $aPid[0]
WinMove($hWindow, '', 0, 0)
Case $aPid[1]
WinMove($hWindow, '', @DesktopWidth - $aPos[2], 0)
Case $aPid[2]
WinMove($hWindow, '', 0, @DesktopHeight - $aPos[3])
Case $aPid[3]
WinMove($hWindow, '', @DesktopWidth - $aPos[2], @DesktopHeight - $aPos[3])
EndSwitch
Next
batch-file alone seems incapable to do this task without external assistance.
You may need something that can handle 4 windows by their handles and move them to position. The 4 windows may need to be recognized by the Process ID to ensure the correct windows are handled.
The code of console4way
is AutoIt3.
The batch file, if executed with /4way
as 1st argument,
will execute console4way.exe. 4 console processes will
execute and a short sleep will happen to allow the windows
to appear.
WinList
will get the console windows by class.
Each window handle is used to get position, size and process ID.
As each process ID is matched, the current window is moved to
a position in the corner of the Desktop as specified.
The width and height of the windows is not specified.
WinMove
allows another 2 parameters for width and height.
$aPos[2]
and $aPos[3]
are the width and height of the
current console window.
Execute the batch file with the argument of /4way
to
initiate the batch file to execute console4way
,
else it will execute without console4way
.
You can add further arguments after the /4way
argument
if you want to pass arguments to the batch file to use.
Compile console4way.au3
to executable to match the bitness of the OS
so that it executes ComSpec of the same environment.
About console4way
console4way
is the command to execute console4way.exe
.
You can have your au3 script named console4way.au3
(which is a text file containing the code above).
Use the au3 script file to compile console4way.exe
with instructions provided.
Once compiled, you only need the batch file and
console4way.exe
to be in the same path and execute
the batch file to test.
You can store the au3 script and use it later
if you want to compile again or update the code.
Instructions to compile console4way.au3
:
with installer:
- Download AutoIt3 and install.
- Rightclick on
console4way.au3
and selectCompile Script (x64)
for 64 bit OS, elseCompile Script (x86)
for 32 bit OS. - In same directory, you should now have a
console4way.exe
.
or with zip:
- Download AutoIt3 and unzip.
- Navigate to
install\Aut2Exe
and executeAut2Exe.exe
. If on a 64 bit OS, you can executeAut2Exe_x64.exe
instead. Either will work the same to compile to x86 or to x64 executable. - Source input is the path to
console4way.au3
. - Leave Destination input empty so it compile to same directory as the script. .exe radio button should be selected.
- Check Compile for System x64 checkbox for 64bit compile.
- Click Convert button to compile.
- In same directory, you should now have a
console4way.exe
.
console4way.exe
will be a self contained executable that can
be executed on an OS without AutoIt installed.
Additional:
Review help page about Compiling Scripts with Aut2Exe.

- 5,262
- 2
- 12
- 22
-
Thanks Micheal for your answer, But still I am bit confuse to implementing the code, could you explain how to implement this code, I mean, console4way is a seperate file, what is console4way.exe, Please tell me about how to implement your code. – VyTcdc Nov 02 '18 at 21:10
-
I added an *About console4way* and *Instructions to compile* section to address your concerns mentioned in your comment. – michael_heath Nov 02 '18 at 23:29