1

In windows I can maximize current window by keyboard shortcut Alt+space then x. When I working on command prompt, can I do same thing using commands (without using shortcuts)? Simply I need to create a bat file , that make windows maximize after run that.

Edit: I need to do this without restarting the command prompt. because restart lost the content of existing window.

Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
  • possible duplicate: http://stackoverflow.com/q/9232308/2152082 – Stephan Jul 30 '14 at 07:02
  • @stephan: absolutely not – Nayana Adassuriya Jul 30 '14 at 07:08
  • no, not after your edit. Nevertheless, the answer there from Bernard Chen might help you. – Stephan Jul 30 '14 at 07:13
  • 1
    You may be able to send key events through a vbscript using cscript maximize.vbs or similar. However, there is a question regarding sending alt-space to a cmd window that you should read: http://stackoverflow.com/questions/7023509/how-to-send-altspace-to-console-window – Petter Nordlander Jul 30 '14 at 07:32
  • similar to what NC ND posted but implemented in Powershell http://stackoverflow.com/questions/4993926/maximize-window-and-bring-it-in-front-with-powershell (you'd need to change some details) – wmz Jul 30 '14 at 10:48

2 Answers2

1

I've not found any reliable way of doing it without a third party tool. So, if you have access to a c compiler, you can build your own

#define  _WIN32_WINNT 0x0500
#include "windows.h"

int main(int argc, char **argv){
    ShowWindow(
        (HWND) GetConsoleWindow(), 
        argc > 1 ? atoi( argv[1] ) : SW_SHOWDEFAULT
    );
    return 0;
}

Tested with mingw/gcc. This code uses the ShowWindow api function to change the show state of the current console window (handle retrieved via GetConsoleWindow()). If compiled to showWindow.exe you can do

showWindow.exe 3 to maximize the window

showWindow.exe 6 to minimize the window

showWindow.exe to return to default mode

See the api documentation for the full list of allowed values.

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • 1
    In theory someone could pinvoke the command in C#, wrap it in powershell, and run from a .bat file without need for an .exe http://www.pinvoke.net/default.aspx/kernel32.getconsolewindow – Knuckle-Dragger Jul 31 '14 at 04:17
0

i think you'll have to check for additional software like autoit or CMDOW

Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103