문제

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top