Frage

I have a script that I need to run as Administrator just as I would right click on cmd.exe and click Run As Administrator.

Currently this is what I have:

Call WSHShell.Run("cmd.exe /K netdom renamecomputer ... end code")
War es hilfreich?

Lösung

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. The "1" is the view mode

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top