bruced
bruced

Reputation: 1

Restore Minimized CMD Window

I have a batch script running in a minimized window. How can I conditionally restore the size of the window and bring it to the foreground?

IF EXIST "temp.txt"  (
    REM How to restore window and bring to foreground?
)

Upvotes: 0

Views: 1310

Answers (1)

tukan
tukan

Reputation: 17365

You should really give us more information.

I'll try to answer it with the general knowledge:

It does not work like that in cmd.
There is, however, a workaround: You can use: START "window title" /max script.cmd.

In your example it would be:

IF EXIST "temp.txt"  (
    START "my max window" /max CMD /C script.cmd
)

Cmd /C .... closes window after execution
OR
Cmd /K. .. leave the window opened after execution

Note: you can always check for more information at start /? when entered on command prompt.

First Edit - I have decided to toss in a simple example for better illustration:

Lets have first file called min_max.cmd:

@ECHO off

ECHO Hello this is original window.
START "min testing" /min CMD /C message.cmd min
START "max testing" /max CMD /K message.cmd max

Then second file would be called message.cmd (both in same directory):

@ECHO OFF

SET "windows_function=%1"
ECHO " -> %windows_function% <- was executed!"
PAUSE

You will see that the minimize window has been minimized, with proper title for easier identification, shows a message and then waits for key press. After pressing any key the window will disappear.

On the other hand the maximized window, with proper title for easier identification, will too wait for the key press but will not disappear afterwards.

Upvotes: 1

Related Questions