Skip to content

Instantly share code, notes, and snippets.

@supersaiyansubtlety
Last active April 17, 2019 22:36
Show Gist options
  • Save supersaiyansubtlety/7b863eae98ba8beb8858f78c3b213c07 to your computer and use it in GitHub Desktop.
Save supersaiyansubtlety/7b863eae98ba8beb8858f78c3b213c07 to your computer and use it in GitHub Desktop.
Run processes from Windows command line without a new terminal window opening

invisible

Run commands on Windows invisibly

This is a very simple vbs script that runs the batch script or command passed to it without anything appearing on screen. If you put it in a folder and add the folder to you user PATH, you can use it as follows:

invisible assoc
invisible echo hello
invisible <command> <with> <args> <"as you'd usually enter it in command line">

You can also do:

"C:\path\to\invisible.vbs" invisible <command> <with> <args> <"as you'd usually enter it in command line">

Personally I use it this way so I can create shortcuts to batch scripts and run them invisibly, then put the shortcuts somewhere useful like in the "Send to" directory.

I wanted to run batch command without a window appearing. Honestly it seems like something like this should be included in command prompt, so I was surprised to find a relative lack of solutions online. I found a couple solutions online, but none were sufficient. A couple places had a version of invisible.vbs, but the way it accepted the command didn't allow for arguments, at least not simply. So I made this.

I haven't tested this outside of my PC, but I expect it should work on any windows machine that can run .vbs's. If run with no arguments vbs will send you an error message (in an uglopuy pp).

This is my first vbs script ever, I made it just because I couldn't find another way to accomplish this. Any feedback is welcome.

'Add this to your path to be able to run programs from cammand prompt without a new terminal window popping up
'Usage: invisible PROCESS ARG "QUOTED ARG" (or however you'd normally run the new process without invisible)
Dim commandNargs
For Each arg In Wscript.Arguments
'Process each argument so they can be forwarded to a background shell
If InStr(arg, " ") = false Then
'No spaces in argument, so no quotes
commandNargs = commandNargs & arg & " "
Else
'Spaces in argument, so enclose in quotes
commandNargs = commandNargs & """" & arg & """" & " "
End If
Next
'Send argument to a background shell
CreateObject("Wscript.Shell").Run commandNargs, 0, False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment