Jump to content
Sign in to follow this  

Winmove dos console problem

Recommended Posts


Would anyone have any ideas why the following code will briefly display a dos window but never in the same position? I am just interested in getting the dos console displayed at the centre of the screen or near to it, consistently.

#include <WinAPI.au3>

;Specify the title for the command window in order to allow it to be moved

$DosTitle = "C:\WINDOWS\system32\cmd.exe"

$pid = Run(@ComSpec & " /c dir", "", @SW_SHOW , 4 + 1)

WinMove($DosTitle, "", @DesktopWidth / 2, @DesktopHeight / 2 , 668,331)

I may be doing something terribly stupid here, I've only recently started to use auto-it.

Thanks for any help you can offer.

Share this post

Link to post
Share on other sites

Hello, machalla,

The short answer is that the system is determining the startup position for the DOS console. You can specify the startup location by doing the following:

1 ) open up a dos console

2 ) right-click on the title bar

3 ) Select Properties

4 ) Select the Layout Tab

5 ) In the Window Position group box, de-select "Let system position window"

6 ) Specify the startup coordinates for Left and Top

Admittedly, this will only work on your machine and will only work for the DOS console. Also, windows created by some batch files or other console applications will have their own settings and thus their own startup locations.

So if you want to go the more programmatic route: I changed your code slightly to present the DOS window, wait for it to exist, then move it to the upper-left hand corner of the screen. See if this works on your machine:

$DosTitle = @SystemDir & "\system32\cmd.exe"
$pid = Run("cmd", "", @SW_SHOW , 4 + 1)
WinWait( "[CLASS:ConsoleWindowClass]" )
WinMove("[CLASS:ConsoleWindowClass]", "", 1, 1, 400, 400, 10)
MsgBox(0, @ScriptName, "Window should have moved")

Hope this helped.

Zach Fisher...

Edited by zfisherdrums

Share this post

Link to post
Share on other sites

Thanks for the help with this zfisherdrums. Your code works fine and I understand now why I was having this problem. Thanks for the concise explanation.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this