当我执行.ps1脚本文件时,我最近收到了Powershell消息“执行策略已更改”消息
--------------
Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
http://go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):
---------------
这是不可接受的,因为我在CurrectUser上设置了不受限制。
----
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Unrestricted <<< HERE
LocalMachine Undefined
----
有谁知道会发生什么???
仅当计算机CPU的负载非常高(超过80%)和/或Powershell没有缓存在RAM上时,才会发生这种情况。
在此先感谢大家!
PS:这是双击行为的mi regedit条目:
HKEY_CLASSES_ROOT \ Microsoft.PowerShellScript.1 \ Shell \ 0 \ Command =
“ C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe”“-命令”“ if(((Get-ExecutionPolicy)-ne'AllSigned'){Set-ExecutionPolicy -Scope Process Bypass};&” C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe“ -Mta-文件'%1'”
尝试这样做以观察一段时间后的行为:
while ($true){
powershell.exe -Command {Get-ExecutionPolicy }
sleep 5
}
由于脚本的执行可能受到限制,因此需要手动将其粘贴到PowerShell中。我目前的假设是,在重新启动/重新擦除内存后,执行策略将更改为,Undefined
直到再次正确加载为止。防止弹出的方式就是-Force
更改。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句