Windows Batch File Without Popup Console

Sometimes you need to schedule a batch file to run some script periodically on a windows server. I found myself having to run one fairly often and it would always pop up that annoying console window whenever I was in the middle of typing something. This sent me searching for a way to run the script without the pop up console window. There was a few ways to do this but I didn’t want to download and install any other software so I went the vbscript route. Here is what I did.

First create a file and call it ‘somefilename.vbs’ and put it in the same directory as the batch file that you want to run.
Next put this code in it :


Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "my-batch-file.bat", 0, False
Set oShell = Nothing

Now when you set up the windows scheduler you want to point it at the ‘.vbs’ file and not the ‘.bat’ file. That seemed to be the easiest and quickest way to get rid of the console popup when running a batch file on a windows server. If anyone has another method that doesn’t require the creation of a new file I would like to hear it. You could always do some reading on vbscript and just code everything in vbscript and not use a batch file at all but I didn’t bother.

Share

5 Responses to “Windows Batch File Without Popup Console”

  • Jon E Says:

    I use a program called Quick Batch File Compiler, it has a “ghost option when compiling the code that hides the console window. Also, it hides your source so the batch file cant be tampered with, but i would only recommend that if your planning on never changing anything in your batch file.

  • Eli Bobeli Says:

    Here’s my variation. Just save this in a vbs with the name of the batch file you would like to execute. So, if you have want to run restartsql.bat, just save this code in restartsql.vbs and it will find the correct file and execute it.

    Set WshShell = WScript.CreateObject(“WScript.Shell”)
    Set oFSO = WScript.CreateObject(“Scripting.FileSystemObject”)
    script = oFSO.GetFile(WScript.ScriptFullName)

    cmd_ext = “.bat”
    cmd_path = oFSO.GetParentFolderName(script)
    cmd_name = Split(oFSO.GetBaseName(script),”.”)(0)

    cmd = cmd_path & “\” & cmd_name & cmd_ext
    Return = WshShell.Run(cmd,0,True)
    set WshShell = Nothing

  • Cody Taylor Says:

    Thanks for the input Eli

  • Umang Jain Says:

    the code given at the top of the page, can it be used in a java prog in place of ,bat file…. i mean, can we call the .vbs file instead of .bat file…..

  • Cody Taylor Says:

    @Umang Jain: I’ve never tried it but I don’t see why it wouldn’t work. Let me know how you fare.

Leave a Reply