سؤال

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")
هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top