简体   繁体   中英

Powershell with elevated permissions through RunOnce

I am trying to run a powershell script using the RunOnce registry key. I need it to run as administrator and I can get the script to run but I can't get it to run with elevated permissions. Here is what I have tried but it doesn't do anything.

My code:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -verb runas -File c:\script.ps1

Any Ideas?

Try powershell.exe -executionpolicy unrestricted -file ..... and remove the set-excecution unrestricted line in your script as it won't have any effect. If powershell is able to read that command in your script file, then it means the script is allowed => execution-policy doesn't need to be changed.

Set-ExecutionPolicy is an interactive command, it does not belong in a script(unless running on a remote computer maybe).

Also, if you're trying to execute it with RunOnce, then make sure it's run using the HKLM RunOnce key to make sure it runs in the SYSTEM context(so it has the proper permissions).

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