简体   繁体   中英

Running script on elevated cmd.exe

How do I ran a script after I open a command window using the below script?

Set objSh = CreateObject("Shell.Application")
objSh.ShellExecute "cmd.exe", "uac" , "", "runas", 1

For example, how do I run ipconfig as an admin using the above script?

If you specify the /c switch, then cmd.exe will carry out the specified command and then terminate.

So, for example:

Set objSh = CreateObject("Shell.Application")
objSh.ShellExecute "cmd.exe /c ipconfig", "uac" , "", "runas", 1

Alternatively, you could use the /k switch, which works exactly the same way, except it keeps the command prompt on the screen once your command finishes executing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM