Open multiple CMD windows running pings, tracert etc and position them on screen

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hiranuk
Posts: 1
Joined: 26 Sep 2024 02:45

Open multiple CMD windows running pings, tracert etc and position them on screen

#1 Post by hiranuk » 26 Sep 2024 02:55

Hi

I have a script that opens 4 x CMD windows and carries out ping, telnet and tracert. When these windows open they open on top of each other. I am looking for a way to position the 4 x CMD windows at each corner of the monitor screen. Is this possible, do i need to add something to the script below.

@echo off
start " ping " 10.0.1.20
start " ping " 8.8.8.8
start " telnet " google.com 443
start " tracert " google.com

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

Re: Open multiple CMD windows running pings, tracert etc and position them on screen

#2 Post by aGerman » 29 Sep 2024 03:49

There is no way to do that in Batch only. I remember a few snippets I wrote for this purpose where Batch calls PowerShell which contains C# code that wraps the Win32 API ... Sounds like a mess and is a mess.
viewtopic.php?f=3&t=8822
viewtopic.php?f=3&t=10439&p=66692#p66682
viewtopic.php?f=3&t=10552&p=67679#p67679
... and a couple more.

That's all quite obsolet because now that even Win 8.1 is a walking dead for almost two years, I assume you're running at least Win 10 where you can use the Windows Terminal. Just run it with the commands executed in another pane of the same tab each.

Code: Select all

@echo off

start wt -M ^
 -p "Command Prompt" --suppressApplicationTitle --title "10.0.1.20" cmd /k "ping /t 10.0.1.20" ;^
 sp -V -p "Command Prompt" --suppressApplicationTitle --title "8.8.8.8" cmd /k "ping /t 8.8.8.8" ;^
 sp -H -p "Command Prompt" --suppressApplicationTitle --title "google.com 443%" cmd /k "telnet google.com 443" ;^
 mf first ;^
 sp -H -p "Command Prompt" --suppressApplicationTitle --title "google.com" cmd /k "tracert google.com"
Steffen
Attachments
panes.png
panes.png (1.28 MiB) Viewed 4569 times

Aacini
Expert
Posts: 1909
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Open multiple CMD windows running pings, tracert etc and position them on screen

#3 Post by Aacini » 29 Sep 2024 18:59

Some time ago I developed a series of Auxiliary .exe programs as aid for Batch files. One of those programs is Window.exe that allows to manage cmd.exe windows in several ways; for example, to position the window at any place in the screen. The Batch file below solve this problem using Window.exe auxiliary program:

Code: Select all

@echo off
setlocal

rem Window.exe example - Distribute 4 cmd.exe windows in the screen
rem Download Window.exe auxiliary program from:
rem https://www.dostips.com/forum/viewtopic.php?f=3&t=3428

rem Get screen size and calculate cmd.exe windows sizes and positions
Window GSize MAX
Window GSize
set /A "posX=(%errorlevel%&0xFFFF)/2+5, posY=(%errorlevel%>>16)/2+10"
Window Size
set /A "cols=(%errorlevel%&0xFFFF)/2, lines=(%errorlevel%>>16)/2-5"

rem Start each one of the four cmd.exe windows
set "PROMPT=$P$_$G"
start "ping 10.0.1.20"     cmd.exe /K mode %cols%,%lines% ^& Window GPos=0,5           ^& ping /t 10.0.1.20
start "ping 8.8.8.8"       cmd.exe /K mode %cols%,%lines% ^& Window GPos=%posX%,5      ^& ping /t 8.8.8.8
start "telnet google.com"  cmd.exe /K mode %cols%,%lines% ^& Window GPos=0,%posY%      ^& telnet google.com 443
start "tracert google.com" cmd.exe /K mode %cols%,%lines% ^& Window GPos=%posX%,%posY% ^& tracert google.com
Image

Antonio

Post Reply