I have a .bat file that I am trying to run in Jenkins. Jenkins is running as a service so wont recognize the pop ups. Is there a way I can run this .bat file in silent mode, or not allow the cmd window to pop up?
Asked
Active
Viewed 60 times
-1
-
A batch file is just a script file which needs a script interpreter. The script interpreter is in this case the *Windows Command Processor* with `%SystemRoot%\System32\cmd.exe` for which is defined by Windows default the environment variable `ComSpec` with that file name as value. `cmd.exe` is a Windows __console__ application. The execution of a batch file from Windows shell (`explorer.exe` running for showing the user a desktop, start menu and taskbar) or a *Windows File Explorer* window (one more instance of `explorer.exe` results always in calling ... – Mofi Aug 24 '23 at 06:11
-
... the Windows kernel library function [CreateProcess](https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessw) with `%ComSpec%` as application to run with the arguments `/c` and the full qualified file name enclosed in `"` as second argument. `explorer.exe` instructs `CreateProcess` to create a console window for the __console__ application `cmd.exe` with using the properties as stored in registry under key `HKEY_CURRENT_USER\Console`. That behavior cannot be changed in any way by a user for a single batch file. – Mofi Aug 24 '23 at 06:13
-
Please show us the lines in the batch file. There is perhaps no batch file needed at all. The general solution for running a console application without a visible console window is using an application which instructs `CreateProcess` with the [process creation flag](https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags) `CREATE_NO_WINDOW` set in function parameter `dwCreationFlags`. The Windows __GUI__ version `%SystemRoot%\System32\wscript.exe` of the *Windows Script Host* is such an application. – Mofi Aug 24 '23 at 06:19
-
A small VBScript file (`.vbs` file) with [.Run](https://ss64.com/vb/run.html) command/function with parameter `intWindowStyle` having value `0` and `bWaitOnReturn` having value `False` is usually used to run a Windows __console__ application completely in background without opening a console window by using a shortcut file (`.lnk` file) with property __Target__ being `%SystemRoot%\System32\wscript.exe "C:\Path\Run Script File.vbs" //B //Nologo`. The usage of `cmd.exe` and a batch file is not needed at all to run a console application with no console window. – Mofi Aug 24 '23 at 06:25
-
So what would i use here , im a bit confused ? – Angela Aug 24 '23 at 06:31
-
there are so many duplicates: [Execute Batch File without Command line visible](https://stackoverflow.com/q/23557720/995714), [how not to open a Cmd window when running a batch file](https://stackoverflow.com/q/33685398/995714), [how to run a command prompt in background using .bat file(not using .vbs file)](https://stackoverflow.com/q/54230872/995714)... – phuclv Aug 24 '23 at 07:08
-
Does this answer your question? [Execute Batch File without Command line visible](https://stackoverflow.com/questions/23557720/execute-batch-file-without-command-line-visible) – phuclv Aug 24 '23 at 07:09
-
What you should do is writing a VBS script file which on interpreting by `%SystemRoot%\System32\wscript.exe` does the same as `%SystemRoot%\System32\cmd.exe` on interpreting the batch file. There is never the need to use to script interpreters `wscript.exe` and `cmd.exe` for one task. Solutions like how to code a VBS script file interpreted by the *Windows Script Host* just run the *Windows Command Processor* for interpreting a batch file without getting a console window displayed are stupid solutions in my point of view.. – Mofi Aug 24 '23 at 19:48
-
Please [edit] your question and show us the command lines in your batch file if you want a more detailed help on the same can be done using VBScript code in a VBS file interpreted by `wscript.exe` without opening any window at all. We cannot help with a precise answer on what to do without knowing what your try to achieve at all other than getting a batch file interpreted by `cmd.exe` without a console window open. We call that an [XY problem](https://xyproblem.info/). You want to run something in background and thought a batch file is the right solution. It is not the right solution. – Mofi Aug 24 '23 at 19:51
1 Answers
1
so then you can use the start
command with /min
and /b
switches to run the .bat file in minimized or background mode.
start /min /b yourfile.bat

Lasantha Karunarathne
- 141
- 3
-
-
using this command start /min /b yourfile.bat , it never seems to end ? – Angela Aug 25 '23 at 04:26