Run cmd.exe as administrator in script

I have a script that I need to run as Administrator, since I would right-click on cmd.exe and click on "Run as administrator".

This is currently what I have:

Call WSHShell.Run("cmd.exe /K netdom renamecomputer ... end code")
+5
source share
1 answer

Have you tried using ShellExecute?

RunCmdElevated.vbs

Set objShell = CreateObject("Shell.Application")
objShell.ShellExecute "cmd.exe", "/k echo test", "", "runas", 1

wscript RunCmdElevated.vbs

gives

Test

C: \ Windows \ system32>

in a new window. "1" is the view mode

http://ss64.com/vb/shellexecute.html

+8
source

All Articles