2

I want to run a batch file in minimized mode by another batch or vbs script. What i tried is:
batch1.bat

@echo off  
start /min batch2.bat

batch2.bat

@echo off  
{my program}  
del /f /q batch1.bat >nul  
del /f /q batch2.bat >nul  

When I try this everything works perfectly the second batch runs and does it's job but at the end a minimized command prompt window stays which says the windows can not fond the batch file and a simple prompt to the path of the batch file as like command prompt shows.

If i use exit command instead of this line del /f /q batch2.bat >nul from the second batch only then it works as i wish but it is important for my program to delete batch2 after it runs.
My only target is to run batch2 in minimized mode.so is there any help?i also cannot use shortcut to batch here.

tshepang
  • 12,111
  • 21
  • 91
  • 136
p2013
  • 438
  • 3
  • 6
  • 12
  • Does this answer your question? [open program minimized via command prompt](https://stackoverflow.com/questions/23057448/open-program-minimized-via-command-prompt) – Evandro Coan Feb 14 '21 at 17:28

5 Answers5

6

From this page:

cmd.exe /c start /min YourBatchFile.bat ^& exit

When running the command from the Task Scheduler, I had to execute cmd.exe as the program and put the rest in as arguments. Also, ^& exit did not close the resulting window for me when run from Windows 8's Task Scheduler. I had to build the exit command into my batch file for it to remove the window from the task bar when it was finished.

Baodad
  • 2,405
  • 2
  • 38
  • 39
  • 1
    You command is wrong. It is missing a `""`, i.e, : `cmd.exe /c start /min "" "YourBatchFile.bat"` [open program minimized via command prompt](https://stackoverflow.com/questions/23057448/open-program-minimized-via-command-prompt) – Evandro Coan Feb 14 '21 at 17:28
5
@echo off

if not "%1" == "min" start /MIN cmd /c %0 min & exit/b >nul 2>&1

:---rest of batch below this line:
abdusco
  • 9,700
  • 2
  • 27
  • 44
Rick Fithen
  • 51
  • 1
  • 1
2

You might try this:

@ECHO OFF &SETLOCAL
{ my program }
DEL "%~f0" /F /Q
Endoro
  • 37,015
  • 8
  • 50
  • 63
1

batch2.bat:

@echo off
{myprogram}
>autoDelete.bat echo del batch1.bat batch2.bat autoDelete.bat
2>nul autoDelete.bat
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • i tried it but this time nothing deleted just a new file autoDelete.bat was created and the cmd window was still there minimized. – p2013 Jul 07 '13 at 18:12
-1

guys i got my problem solved while surfing on stackoverflow questions. check out the answers of this question you will find the answer.
.vbs script won't run batch / how to run batch silently

NirCMD exec hide "Path to Batch File\Batch File.bat"

download nircmd from here
Official site: http://www.nirsoft.net/utils/nircmd2.html

Community
  • 1
  • 1
p2013
  • 438
  • 3
  • 6
  • 12