6

I'm wondering if there is a way to minimize a batch window after it runs a certain command. I already know start /min and tricks to START the window minimized but what about while it's running a loop or timeout?

Let's say:

echo Hello!
timeout /t 100
:COMMAND TO MINIMIZE WINDOW WHILE TIMEOUT IS RUNNING

Right now i'm calling an autoit script in the bat file to hide the window while the command is running with :

WinSetState($application_name, "", @SW_HIDE) 

but i'm looking for a pure batch/powershell/vbs solution that can be coded directly in the .bat file.

Thank you for your time!

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Rakha
  • 1,874
  • 3
  • 26
  • 60

4 Answers4

13

Use PowerShell's invocation options, executing no command or script.

@echo off & setlocal

echo Hello!
powershell -window minimized -command ""
timeout /t 100
powershell -window normal -command ""

FWIW, -window hidden is also available if you wish.

rojo
  • 24,000
  • 5
  • 55
  • 101
4

You can also minimize all windows by using below code with powershell.

$shell = New-Object -ComObject "Shell.Application"
$shell.minimizeall()

Check: https://techibee.com/powershell/powershell-minimize-all-windows/1017

KingRider
  • 2,140
  • 25
  • 23
1

You can minimize the command prompt on during the run but you'll need two additional scripts: windowMode and getCmdPid.bat:

@echo off
echo Hello!
call getCmdPid >nul
call windowMode -pid %errorlevel% -mode minimized

timeout /t 100
call getCmdPid >nul
call windowMode -pid %errorlevel% -mode normal
npocmaka
  • 55,367
  • 18
  • 148
  • 187
0

This will do. You need to however run the minimize before the timeout as it is in batch. Timeout will now occur once the window is minimized. This example will keep the window during the ping so you can see it minimizes.

echo Hello!
ping 127.0.0.1
if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
timeout /t 100
exit
Gerhard
  • 22,678
  • 7
  • 27
  • 43