ShellExecute method

Run a script or application in the Windows Shell.

Syntax
 .ShellExecute "application", "parameters", "dir", "verb", window
 .ShellExecute 'some program.exe', '"some parameters with spaces"', , "runas", 1
Key
 application The file to execute (required).
 parameters Arguments for the executable.
 dir Working directory, when runas is used to elevate the session this will reset the
 directory, meaning this option will have no effect.
 verb The operation to execute (runas/open/edit/print).
 window View mode application window.
 normal=1, hide=0, 2=Min, 3=max, 4=restore, 5=current, 7=min/inactive, 10=default

Note that double " and single ' quotes that can be used to delimit paths with spaces.

The runas verb can be used to elevate permissions. This was undocumented up until 2020 but is now official. When a script is run with elevated permissions several aspects of the user environment may change: The current directory, the current TEMP folder and any mapped drives will be disconnected.

runas will fail if you are running in WOW64 (a 32 bit process on 64 bit windows) for example %systemroot%\syswow64\cmd.exe ...

The ShellExecute method is a member of the IShellDispatch2 object.

Examples

Run a batch script with elevated permissions, flag=runas:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "E:\demo\batchScript.cmd", "", "", "runas", 1

Run a VBScript with elevated permissions, flag=runas:

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cscript", "E:\demo\vbscript.vbs", "", "runas", 1

A batch file to launch CMD.exe as admin in the directory C:\batch\:

Admin.cmd

@Echo off
cscript getadmin.vbs

getadmin.vbs

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cmd.exe", "/k CD C:\batch\ ", "", "runas", 1

"If you don’t execute your ideas, they die" ~ Roger Von Oech

Related VBScript commands

Run with elevated permissions - Script to run as Admin.
.Exec - Execute command, returning an object.
.Run - Run a command.
joeware.net - CPAU (Create Process As User) like RunAs but with an option to encrypt the password.
Equivalent CMD command: ShellRunAs - Run a command under a different user account.

(追記) (追記ここまで)
Copyright © 1999-2026 SS64.com
Some rights reserved

AltStyle によって変換されたページ (->オリジナル) /