30

I have a shortcut running this command when clicked: cmd /c "full path to my batch file". When I use it, it does what it is supposed to do, but in the process the ugly console window pops up. Is there any way to make this command start a hidden or at least minimized window?

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
kno010
  • 411
  • 1
  • 4
  • 5
  • 1
    It shouldn't show, but windows has a history of doing things differently, so really there isn't an easy way. You are better off creating a service if you really want it to run in the background. – arielnmz Aug 07 '17 at 14:36
  • in the shortcut there is a dropdown under the command where you can choose Normal Window or Minimized – Jerry Jeremiah Aug 07 '17 at 14:38

7 Answers7

22

Use the command start with switch /min to start cmd in minimized window:

start /min cmd /c "full path to my batch file"
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Stephan
  • 53,940
  • 10
  • 58
  • 91
16
powershell "start <path of batch file> -Args \"<batch file args>\" -WindowStyle Hidden"

This can be placed in a separate batch file which, when called, will terminate immediately while your batch file executes in the background.

From ' Args ' to ' \" ' can be excluded if your batch file has no arguments.

' -v runAs' can be added before the end quote to run your batch file as an administrator.

NoDataDumpNoContribution
  • 10,591
  • 9
  • 64
  • 104
Stego27
  • 169
  • 1
  • 2
6

I found this solution :

Create a launch.vbs file and add

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

Replace "C:\Batch Files\syncfiles.bat" by your absolute or relative path file name.

Source : https://www.winhelponline.com/blog/run-bat-files-invisibly-without-displaying-command-prompt/

Source MSDN : https://msdn.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx

Shim-Sao
  • 2,026
  • 2
  • 18
  • 23
3

Right-click on the shortcut icon and choose "Properties."

On the "Shortcut" tab, choose the "Run" type you desire from the dropdown menu.

The START command has a /B switch to start without creating a window. Use START /? to read all about it.

lit
  • 14,456
  • 10
  • 65
  • 119
3

Use AutoHotKey file. Download and install AutoHotKey first.

suppose you have an 1.bat

you'll create a C:\2.ahk, whose content is

Run C:\1.bat,,Hide
return

and you'll create a 3.lnk, and right click it, click property, then set the Target to

"C:\Program Files\AutoHotkey\AutoHotkey.exe" C:\2.ahk

Then you'll get what you want.

This way, you can attach the 3.lnk to your taskbar or start menu, and also change its icon.

The start method can only be used in a bat, which can't be added to taskbar or changed icon.

1

This will create a separate process (without a window), and not block parent window so it can continue your main work:

start /b cmd /c "full path to my batch file"
Zimba
  • 2,854
  • 18
  • 26
0

Create a VBScript file as a shell to start it.

' Launcher.vbs
If WScript.Arguments.Count = 0 Then
  WScript.Quit 1
End If

Dim WSH
Set WSH = CreateObject("WScript.Shell")
WSH.Run "cmd /c " & WScript.Arguments(0), 0, False

You may want to embed this as a Here Document in your batch file. See heredoc for Windows batch?

iBug
  • 35,554
  • 7
  • 89
  • 134
  • Make sure that wscript.exe runs .vbs files instead of cscript.exe, else a console will briefly flash. You can configure this from the command prompt via `cscript //H:WScript`. Using wscript.exe should be the default. – Eryk Sun Aug 07 '17 at 21:40
  • 2
    In general you need quotes around the argument, e.g. `WSH.Run "cmd /c """ & WScript.Arguments(0) & """", 0, False`. Otherwise CMD will mess up the quoting when it strips the first and last quote in case the command starts with a quoted path for the executable and there's at least one more quoted argument in the command line. – Eryk Sun Aug 07 '17 at 21:42