How can I run a windows batch file but hiding the command window? I dont want cmd.exe to be visible on screen when the file is being executed. Is this possible?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you write an unmanaged program and use CreateProcess API then you should initialize
lpStartupInfoparameter of the type STARTUPINFO so thatwShowWindowfield of the struct is SW_HIDE and not forget to useSTARTF_USESHOWWINDOWflag in thedwFlagsfield of STARTUPINFO. Another method is to use CREATE_NO_WINDOW flag ofdwCreationFlagsparameter. The same trick work also with ShellExecute and ShellExecuteEx functions.If you write a managed application you should follows advices from http://blogs.msdn.com/b/jmstall/archive/2006/09/28/createnowindow.aspx: initialize
ProcessStartInfowithCreateNoWindow = trueandUseShellExecute = falseand then use as a parameter of . Exactly like in case of you can set propertyWindowStyleofProcessStartInfotoProcessWindowStyle.Hiddeninstead or together withCreateNoWindow = true.You can use a VBS script which you start with wcsript.exe. Inside the script you can use
CreateObject("WScript.Shell")and then Run with 0 as the second (intWindowStyle) parameter. See http://www.robvanderwoude.com/files/runnhide_vbs.txt as an example. I can continue with Kix, PowerShell and so on.If you don’t want to write any program you can use any existing utility like CMDOW /RUN /HID "c:\SomeDir\MyBatch.cmd", hstart /NOWINDOW /D=c:\scripts "c:\scripts\mybatch.bat", hstart /NOCONSOLE "batch_file_1.bat" which do exactly the same. I am sure that you will find much more such kind of free utilities.
In some scenario (for example starting from UNC path) it is important to set also a working directory to some local path (
%SystemRoot%\system32work always). This can be important for usage any from above listed variants of starting hidden batch.