How can I hide ms-dos window when running a .bat file? How can I hide ms-dos window when running a .bat file? windows windows

How can I hide ms-dos window when running a .bat file?


Use a VBScript

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("C:\yourbatch.bat"), 0, True

Run that which will run your batch file hidden.


I don't like VBScript solution.

Download and copy nircmd.exe to your %systemroot%\system32 folder, then add this command to first line of your batch:

nircmd.exe win hide ititle "cmd.exe"

or make your batch title custom first with title command to avoid from hiding all cmd windows, like this:

title MyBatchnircmd.exe win hide ititle "MyBatch"


This VBScript creates a copy of your batch file in %Temp%, executes it silently and deletes it afterwards

Dim fsoSet fso = CreateObject("Scripting.FileSystemObject")Dim tempfolderConst TemporaryFolder = 2Dim WshShell, strCurDirSet WshShell = CreateObject("WScript.Shell")strCurDir    = WshShell.CurrentDirectorybatch = "@ECHO OFF" & vbCrLf & _        "C:\wamp\bin\php\php5.4.3\php.exe -f C:\wamp\www\tst\index.php"Set tempfolder = fso.GetSpecialFolder(TemporaryFolder)WshShell.CurrentDirectory = tempfolderi=1n=0While n <> 1If (fso.FileExists(i&".bat")) Then  i = i + 1Else  n = 1End IfWendSet File = fso.CreateTextFile(i&".bat",True)File.Write batchFile.CloseDim batchfilebatchfile = fso.GetAbsolutePathName(i&".bat")WshShell.CurrentDirectory = strCurDirWshShell.Run chr(34) & batchfile & Chr(34), 0, TRUEfso.DeleteFile batchfile