Reputation: 451
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?
Upvotes: 34
Views: 100805
Reputation: 51
Inspired by @user10249692 I wrote a generic "hidden start" AutoHotKey script hstart.ahk:
; Abstract: hidden start
; start an application with a hidden window
;
; Usage: hstart [-d] <app> [<arg1>...<argn>]
;
; -d shows the Run command argument and does not hide the app's window
;
; 2025 Jan 2 jhm original creation
;
#NoTrayIcon
if (a_args[1] = "-d") {
debug := 1
runOption := ""
a_args.RemoveAt(1)
} else {
debug := 0
runOption := "Hide"
}
if (!FileExist(a_args[1])) {
MsgBox, % a_args[1] . " file does not exist"
exit
}
if (debug) {
MsgBox, % Join(" ",a_args*)
}
Run, % Join(" ",a_args*),,% runOption
exit
Join(sep, params*) {
for index, param in params
str .= param . sep
return SubStr(str, 1, -StrLen(sep))
}
Consider using the AutoHotKey ahk2exe compiler to add hstart.exe to your utility bin!
Upvotes: 0
Reputation: 319
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.
Upvotes: 21
Reputation:
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.
Upvotes: 4
Reputation: 3691
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"
Upvotes: 2
Reputation: 56208
Use the command start
with switch /min
to start cmd
in minimized window:
start /min cmd /c "full path to my batch file"
Upvotes: 25
Reputation: 2126
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
Upvotes: 9
Reputation: 16266
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.
Upvotes: 4
Reputation: 37307
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?
Upvotes: 0