How can a batch file run a program and set the position and size of the window?

Here is an alternate way with nircmd util from http://www.nirsoft.net/utils/nircmd.html
Examples:

nircmd win move ititle “cmd.exe” 5 5 10 10
nircmd win setsize ititle “cmd.exe” 30 30 100 200
nircmd cmdwait 1000 win setsize ititle “cmd.exe” 30 30 1000 600

Here are the contents of SetEnv.cmd:

    Explorer /n,c:\develop\jboss-4.2.3.GA\server\default\deploy
    nircmd wait 1000 win setsize ititle "something" x, y, width, height
    Explorer /n,c:\develop\Project\Mapping\deploy
    nircmd wait 1000 win setsize ititle "something" x, y, width, height

Where x,y top left corner location and width,height are the window size
“something” is window title usually the folder name eg. “c:\develop\jboss-4.2.3.GA\server\default\deploy”
The “wait” may need to be adjusted to give the time for the application window to initialize. So you would increase time if you have virus scanners that delay. Not so much a problem with explorer.exe or cmd.exe but something like Firefox’s or java applications can vary from few seconds to several dozen seconds depending on the speed your hardware and OS tuning. You can also customize cmd.exe window or the “run” application by adding lines to “SetupEnvCmd.cmd assuming “run” is asynchronous win32 application otherwise add “start” command.

Leave a Comment