4

I was just wonderin' in a .bat file, if there was a way to call an external .bat file, or even an *.exe and make it open so it 'snaps' to the top left hand corner of the screen ?

Cheers

latonz
  • 1,601
  • 10
  • 21
user226973
  • 53
  • 1
  • 3

4 Answers4

3

There is no direct way to position a Window from the Windows command prompt. You basically have the following options:

  • Use a GUI automation tool, e.g. AutoHotkey which lets you script window actions. AutoHotkey e.g. offers the WinMove command:

    Run, calc.exe
    WinWait, Calculator
    WinMove, 0, 0 ; Move the window found by WinWait to the upper-left corner of the screen.
    
  • Use PowerShell, e.g. with the WASP snapin (http://wasp.codeplex.com/).

  • Write a short program in C/C++/.NET that will position the active Window at position 0,0 of your main screen.

A very basic program in C#, that takes a window caption as parameter could look like that:

using System;
using System.Runtime.InteropServices;

class Program
{
    public const int SWP_NOSIZE = 0x0001;
    public const int SWP_NOZORDER = 0x0004;

    [DllImport("user32.dll", SetLastError = true)]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);

    [DllImport("user32.dll", SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    static void Main(string[] args)
    {
        IntPtr handle = FindWindow(null, args[0]);
        SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
    }
}
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • I gave you the answer for this one. But I am going to use both yours and Francis's method. My main script calls on several .bat files and executables as well. AutoHotKey method looks easier; not that I've used AutoHotKey before. +1 to Knowledge :) – user226973 Dec 10 '09 at 02:04
1

in cmd box type help start.

example: start /MAX "xxx.bat"

Francis
  • 11,388
  • 2
  • 33
  • 37
  • 1
    That will start the window maximized. What the OP wants is a window snapped to the top left corner of the screen. – Dirk Vollmar Dec 09 '09 at 09:15
  • for cmd(bat), the window will be snapped to top left when being maximized. – Francis Dec 09 '09 at 10:27
  • Thanks Francis. Not 'THE' answer I was lookin' for, but it does somewhat help me out. I forgot about the /MAX switch for 'start'. I think I will use this for calling my .bat files, and the AutoHotKey for the apps. Thanks a mil! – user226973 Dec 10 '09 at 02:05
0

Use the start command.

Klaus Byskov Pedersen
  • 117,245
  • 29
  • 183
  • 222
0

It's a bit messy but I think it can be done.

You will need to install two programs:
AutoIt
Winsplit Revolution

Create an autoit script to:
1. open the program or batch file you want
2. Wait untill the program is open
3. Make the program the active window
4. Call a ctrl+alt+7, "Send("^!7")" (Winsplit Revolution shortcut to send program to top left corner)
5. End script

If i have time later I'll try to script it

JoeOD
  • 129
  • 2
  • 5
  • 13