I was looking for a way to start elevated (i.e. administrator permissions) and/or invisible processes via batch in Windows. It turns out that this is kind of impossible with batch only, so I googled some vbs stuff and hacked it all together into a neat command line power utility.

The interface is as follows:

exec [/action: elevate, open, read, print] [/display: hide, show] exe [arguments]

/action defaults to open. /display defaults to show. exe is the path to an executeable, could be a script, image, whatever as well. arguments are applied to the exe.

Example: This starts a background node.js deamon with admin rights.

exec /action:elevate /display:hide node myDeamon.js

Everything works just fine, but I'm pretty sure that it's not perfect yet, as I basically have no idea about VBScript. I'd like to hear your opinions or ideas!

Set objShell = CreateObject("Shell.Application")

intOffset = 0

' get action
strAction = "open"
If (WScript.Arguments.Named.Exists("action")) Then
  intOffset = intOffset + 1
  Select Case WScript.Arguments.Named.Item("action")
        Case "elevate" strAction = "runas"
        Case "open" strAction = "open"
        Case "read" strAction = "read"
        Case "print" strAction = "print"
        Case Else strAction = "open"
    End Select
End If

' get display mode
intMode = 1
If (WScript.Arguments.Named.Exists("display")) Then
    intOffset = intOffset + 1
    Select Case WScript.Arguments.Named.Item("display")
        Case "0" intMode = 0
        Case "false" intMode = 0
        Case "hide" intMode = 0
        Case "hidden" intMode = 0
        Case Else intMode = 1
    End Select
End If

' get application to execute
strApplication = WScript.Arguments(intOffset)

' get arguments
strArguments = ""
For i = intOffset+1 To WScript.Arguments.Count-1
    strArguments = strArguments & WScript.Arguments(i)

' execute application
If (WScript.Arguments.Count >= 1) Then
    objShell.ShellExecute strApplication, strArguments, "", strAction, intMode
End If


  • 1
    \$\begingroup\$ silvinci, please include the relevant code directly in your question as required by the faq. \$\endgroup\$
    – Adam
    Commented Dec 14, 2012 at 9:18
  • \$\begingroup\$ Done. Just thought it would be too lengthy. \$\endgroup\$
    – buschtoens
    Commented Dec 15, 2012 at 1:46

1 Answer 1


The number one improvement you can make is to include Option Explicit as the first line of your script and explicitly declare your variables using Dim. This will save you a lot of heartache in the future (e.g., if you make a typo in a variable name, it becomes a runtime error, instead of just silently creating a new variable).

  • \$\begingroup\$ This sounds pretty reasonable. Thanks. Do I have to Dim in For statements? \$\endgroup\$
    – buschtoens
    Commented Mar 17, 2013 at 12:09
  • \$\begingroup\$ If you have a statement For i = 1 To 10, then you must declare i with Dim i, if that's what you're asking. \$\endgroup\$ Commented Mar 17, 2013 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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