1

I could not find a good answer for my problem. Perhaps someone has already the answer and would be very kind to share it. I am running a batch file and, at a certain time, I would like to minimize the batch window. Some codes later, maximize or return it to the actual size.

@echo off
mode con cols=100 lines=100
echo My batch is NOT minimized. This message is from a normal window! 
start "window_will_be_minimized" k:\Folder20\MiniMaxi.exe 
start /wait "" cmd /c c:\Folder00\Drawing.exe

Drawing.exe is now running.

REM --- At this point my batch window is minimized and the MiniMaxi.exe is closed
REM --- until the Drawing.exe is closed.

Drawing.exe is now closed.

REM --- Immediatelly my batch window must return to its previous size.
        Therefore, the MiniMaxi.exe will be launched and then closed

start "window_will_be_MAXImized" k:\Folder20\MiniMaxi.exe
echo Again, this message is from a normal window
pause > nul
exit /b

Thank you in advance

Luiz Vaughan
  • 675
  • 1
  • 15
  • 33
  • 1
    Related question: [Letting a Batch file Minimize a DOS window](http://stackoverflow.com/questions/775703/letting-a-batch-file-minimize-a-dos-window) – Eitan T Aug 26 '12 at 09:06
  • Thanks EitanT, but this link you added does not clearly explain how to minimize window while running the batch. The explanations there were unclear and untested – Luiz Vaughan Aug 29 '12 at 04:30
  • Well, it _does_ show you how to make a basic C++ program that minimizes a window with a title of choice. That is essentially what you want, no? – Eitan T Aug 29 '12 at 06:50
  • 1
    There is no straight forward way of doing this. Everything I've seen involves using **at least** jscript and knowing the window to minimize's ID#. I believe EitanT's suggestion is best. – James K Aug 29 '12 at 15:16
  • @EitanT ; James K - Thank you for your aswer but I have no clue how to implement that post"Lettting a Batch file Minimize a DOS window" to my batch script above. Can someone write a tutorial step by step? – Luiz Vaughan Sep 07 '12 at 22:52
  • There's a tool called [cmdow](http://www.commandline.co.uk/cmdow/) that could do that, but may trigger security software as it's occasionally used to hide nefarious processes. – Jim Davis Aug 23 '15 at 09:28

2 Answers2

1

Bad news: batch files cannot control whether their own window is min or max; this must be done when calling a batch file, at which time you can tell it to run /min, /max, or neither/default. The new batch will not be aware of this setting. As EitanT mentioned, it will have to be managed by an application. Only when starting a new batch can you control if that one will be min, max, or normal.

For timing, the only control you have is either pause (as you did in your script), or some method of delaying the continuation of the script by doing something like this delay of about 10 seconds:

ping -n 10 localhost >nul
Lizz
  • 1,442
  • 5
  • 25
  • 51
  • Thank you for your answer but I cannot close my batch and immediatelly open a new batch (something as a mirror) that will be then minimized. The way my batch is configured and the way it must be, when it closes it triggers some hidden "cleanup" functonalities. The timming is not necessary in here. – Luiz Vaughan Sep 07 '12 at 22:59
  • I wish I knew of some way to help. But batch files offer no way to control their *own* size or location. They would have to interactively, dynamically control themselves and batch can't do that. The only way to possibly gethis to work is have them spawn each other, which would be painful - bu possible. Need help with that? – Lizz Sep 08 '12 at 00:20
  • Yes, you could help :). How to write the MiniMaxi.exe (or *.vbs) program? The tile of my batch is "MyBatch". The minimizer would catch the batch window called "MyBatch" and then minimized if not already minimized OR would maximize it if not already maximized. Please see my edited question at the top. – Luiz Vaughan Sep 08 '12 at 19:06
  • Sounds like you're agreeing with EitanT: the solution is to write a custom app. freelancer.com is a site where you can pay someone to write apps. – Lizz Sep 09 '12 at 04:28
  • @Lizz-If I'd demanded 0.5$ for every code I had written for free in all the programming sites and discussion boards I visited so far (just because I feel good helping anonymous people that, in many circumstances, have also freely given their weekend hours to help me out willingly and heartedly without even knowing who I am or where I live) I would possibly be one of the richest man on earth. Being useful and the sensation it triggers since it delivers a positive impact on somebody’s live is something beautiful. Unfortunately, I cannot just recommend people to being useful. One should try. – Luiz Vaughan Sep 09 '12 at 23:27
  • I wanted to help but I don't code, and my understanding is this is a site to assist in troubleshooting something that's already been started. Given those conditions I was trying to give you options you may not have known, not to sound heartless. If I could write code then perhaps this one would be simple enough to help in some way. Unfortunately it is not in my skill set. A large part of my life purpose is to help, but I don't have what's needed in this case. – Lizz Sep 10 '12 at 03:42
0

I cannot do what you ask however, as mentioned you can spawn batch files in a minimised, maximised or default state. The following will create a new batch xmise.bat start it minimised & exit. The new batch xmise.bat will start Drawing.exe, wait, launch the original batch (custom sized window) & exit. Then the original batch will delete the created batch xmise.bat.

You could write the

somes codes later / hidden "cleanup" functonalities

to xmise.bat

@echo off
mode con cols=100 lines=100
if "%var%"=="" echo My batch is NOT minimized. This message is from a normal window!
if "%var%"=="created" echo Again, this message is from a normal window
pause>nul 
if "%var%"=="created" del xmise.bat&cls&goto :end
set var=created
echo start /wait "" "Drawing.exe">xmise.bat
echo start "" cmd /c "%~n0.bat">>xmise.bat
echo exit>>xmise.bat
start /min xmise.bat
:end
exit

Drawing.exe is now running.

REM --- At this point the xmise.bat window is minimized and the original.bat (%~n0.bat) exits
REM --- until the Drawing.exe is closed.

Drawing.exe is now closed.

REM --- Immediatelly my batch window must return to its previous size.
REM --- the original.bat will be relaunched custom size, xmise.bat exits, & then is deleted.
Terence
  • 128
  • 1
  • 5