0

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?
)
bruced
  • 1
  • 2
  • 2
    please share your code – DevB2F Nov 12 '17 at 19:40
  • Please [edit](https://stackoverflow.com/posts/47252999/edit) your question and add your code ! – Hackoo Nov 13 '17 at 09:41
  • 2
    Possible duplicate of ["Bring to front" for Windows XP command shell](https://stackoverflow.com/questions/557166/bring-to-front-for-windows-xp-command-shell) – MatSnow Nov 13 '17 at 16:49
  • @MatSnow: actually the linked solutions do not give proper answer using native command prompt tools. Which I have attempted to do below. – tukan Nov 15 '17 at 07:59
  • @tukan There is an answer where the start of a second batch is suggested. Not as detailed as your answer, but roughly the same idea. – MatSnow Nov 15 '17 at 08:59
  • @MatSnow Yes there is a simple answer without proper details, which I have read after posting my answer. As you know, the devil is always in details. I try to post every time tested code as there could be multiple catches like running the command without `CMD` and the switches which makes huge difference. – tukan Nov 15 '17 at 10:05

1 Answers1

1

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.

tukan
  • 17,050
  • 1
  • 20
  • 48