views:

175

answers:

4

Hi guys 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

A: 

Use the start command.

klausbyskov
A: 

in cmd box type help start.

example: start /MAX "xxx.bat"

Francis
That will start the window maximized. What the OP wants is a window snapped to the top left corner of the screen.
0xA3
for cmd(bat), the window will be snapped to top left when being maximized.
Francis
cmd will also be started maximized by this command.
0xA3
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!
PS - I can't 'up vote' yet sorry. Not enough rep.
+1  A: 

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);
    }
}
0xA3
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 :)
A: 

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