简体   繁体   中英

How can I execute a powershell command as admin from VBS?

I currently have a VBScript that allows me to call arbitrary powershell commands, which includes entire powershell scripts. When I call them I cannot set the execution policy due to registry restrictions. Meaning, powershell isn't running as administrator.

How can I change this?

I believe the following is the section of the VBScript that is calling powershell.exe

cmd = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -OutputFormat text -EncodedCommand " & b64 & " > " & logstd & " 2> " & logerr

有多种方法可以使进程升级,但对于这种用例,我认为您应该在命令行中指定执行策略:

cmd = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -OutputFormat text -EncodedCommand " & b64 & " > " & logstd & " 2> " & logerr

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