mhopkins321
mhopkins321

Reputation: 3083

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

Upvotes: 0

Views: 5607

Answers (1)

Segfault
Segfault

Reputation: 8290

There are various ways you can make a process run elevated but for this use case, I think you should just specify the execution policy in the command line:

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

Upvotes: 2

Related Questions