Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute Batch File without Command line visible

Tags:

batch-file

cmd

I have to run a batch file without showing the command line but the Command line keeps on popping up. This is my code:

@echo off
:SAMPLE
cd /d C:
md %RANDOM%
cd /d D:
md %RANDOM%
cd /d E:
md %RANDOM%
goto SAMPLE
like image 341
MissJ Avatar asked May 09 '14 06:05

MissJ


People also ask

How do I run a command prompt in the background?

If you know you want to run a command in the background, type an ampersand (&) after the command as shown in the following example. The number that follows is the process id. The command bigjob will now run in the background, and you can continue to type other commands.


2 Answers

Solution-1:

Save your code in a batch file lets say My.bat

Create a VBScript file lets say Master.vbs and call your My.bat file within it.

Lets assume your batch file is at C:\Test\My.bat then:

Master.vbs:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Test\My.bat" & Chr(34), 0
Set WshShell = Nothing

It'll run your batch file in invisible/hidden mode.

Solution-2:

If at all possible, modify the batch file to run whatever program with the start command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you’ll only see the taskbar flash without even seeing a window onscreen.

like image 200
Sunny Avatar answered Oct 21 '22 17:10

Sunny


The following sample code works

start cmd /c "some command && exit 0"

The trick is => && exit 0

like image 39
sanbrother Avatar answered Oct 21 '22 16:10

sanbrother