Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On WinXP, can I run a batch (.bat or .cmd) file, via a shortcut, without a "black window" ?

share|improve this question
2  
Are you asking if you can prevent the command window from showing up when you run a bat file? –  Eric U. May 11 '10 at 17:36
    
Yes, you can easily change the default color of the output window by using the Properties on a cmd.exe shortcut. (yes this is a joke...) –  Toby J Jan 10 at 17:45
add comment

migrated from stackoverflow.com May 11 '10 at 18:32

This question came from our site for professional and enthusiast programmers.

8 Answers

Just to expand on the "Use Windows Scripting" answers (which I consider best because it's built-in already) here's how to do it by passing the name of the "real" batch file as a parameter:

If WScript.Arguments.Count = 1 Then
    CreateObject("Wscript.Shell").Run WScript.Arguments.Item(0), 0, True
End If

So e.g. save the above file as HideCmd.vbs somewhere then call:

HideCmd.vbs c:\foo\my_batch_file.bat

Finally, if you're looking to run this from somewhere that doesn't understand the .vbs file (such as an "External Tools" in Visual Studio), you'll want to call C:\Windows\System32\wscript.exe with the vbs file as its first parameter and your batch file as the second.

share|improve this answer
add comment

You can use window scripting such as AutoIt.

As an example, just write this to the AutoIt script editor.Its fairly simple

Run("C:\test\batchfile.bat", "", @SW_HIDE)

If you want to run it in a loop,

$x=0
Do
 Run("C:\test\batchfile.bat", "", @SW_HIDE)
 Sleep(5000)
Until $x = 1

Compile it as .exe - and you are done.

share|improve this answer
add comment

Free GPL open source "Create Hidden Process"

http://www.commandline.co.uk/chp/

Microsoft Security Essentials, and probably most other virus/malware scanners will treat the executable, chp.exe, as a virus because it hides whatever program you specify from displaying a window or a task bar button, just like viruses do.

It's not a virus. It doesn't hide the target process from appearing in task manager for example. And of course the source code is included so you can see that it's very small and doesn't do anything but run whatever program you give it.

You don't even have to trust that the included chp.exe really was built from that source. You can go ahead and discard the included chp.exe and compile your own from the source, and all the necessary tools to do so are even free and downloadable.


You can also just make a shortcut to the .bat or .cmd file, then right-click on the shortcut, Properties, Shortcut tab, Run: Minimized. Then in scheduled tasks, use the shortcut instead of the .bat/.cmd file directly. That will prevent a window from popping up, but a taskbar button will still appear.

share|improve this answer
add comment

Use Hidden Start

Hidden Start - Run Applications and Batch Files without a Console Window or UAC Prompt

Console applications and batch files are regularly run at Windows startup or in a schedule. The main inconvenience of this is that each application opens a console window that flickers on the screen. Hidden Start (or Hstart) is a lightweight command line utility that allows you to run console applications and batch files without any window in the background, handle UAC privilege elevation under Windows 7 and Vista, start multiple commands in parallel or synchronously, and much more.

enter image description here

share|improve this answer
add comment

This is just a simplification of Shaji's answer. You can run your batch script through a vbs script like this:

'HideBat.vbs
CreateObject("Wscript.Shell").Run "your_batch_file.bat", 0, True

This will execute your batch file with no cmd window shown.

share|improve this answer
add comment

Save the following as wscript, for instance, hidecmd.vbs after replacing "testing.bat" with your batch file's name.

Set oShell = CreateObject ("Wscript.Shell") 
Dim strArgs
strArgs = "cmd /c testing.bat"
oShell.Run strArgs, 0, false

The reference is here http://msdn.microsoft.com/en-us/library/d5fk67ky.aspx

share|improve this answer
add comment

You can change the properties of the of the shortcut to run minimized.

To run it completely invisibly you'll need something else like Windows Scripting.

share|improve this answer
    
Your first suggestion is the way I've always done it. –  martineau Mar 19 '12 at 23:32
add comment

Use start with the '/B' option. For example:

@echo off
start /B go.bat
share|improve this answer
12  
start /b will just run the program in the currently-allocated console instead of spawning a new one. You'll get a new one anyway since the batch has to run with cmd (which, in turn [surprise], opens a console). –  Joey May 11 '10 at 18:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.