Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

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

I have batch file that sets up the desktop environment for me when I am writing code. The file is named: SetEnv.cmd and it opens 3 other windows:

  1. An instance of Windows Explorer that is set to the app server's deploy directory.
  2. A second instance of Windows Explorer that is set to the directory where my deployment file is written.
  3. A console window to start my application server.

Here are the contents of SetEnv.cmd:

Explorer /n,c:developjboss-4.2.3.GAserverdefaultdeploy
Explorer /n,c:developProjectMappingdeploy
cmd /c SetupEnvCmd.cmd

And here are the contents of SetupEnvCmd.cmd:

cd C:developjboss-4.2.3.GAin
run

Every time I run this, I have to waste time rearranging and resizing the windows. I don't want to run the windows minimized, because I interact with each window many times while writing and testing code. Is there any way I can control the position and/or size of the windows that are opened from within the script?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:developjboss-4.2.3.GAserverdefaultdeploy
    nircmd wait 1000 win setsize ititle "something" x, y, width, height
    Explorer /n,c:developProjectMappingdeploy
    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:developjboss-4.2.3.GAserverdefaultdeploy" 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...