我有一个简单的自动热键脚本
!+l:: RunWait, PowerShell -NoExit -C "Import-Module D:\projects\changescreensaver\changescreensaver.psm1; Set-ScreenSaverTimeout 1;"
但它不会让我加载我的 ps 配置文件或执行 import-module 并给我一个执行策略错误:
Import-Module : File D:\projects\changescreensaver\changescreensaver.psm1 cannot be loaded because running scripts is
disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
在我的终端上,Get-ExecutionPolicy -List
返回
C:\Users\someone>Get-ExecutionPolicy -List
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine RemoteSigned
但在我的脚本中,返回
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
我可以通过它-ExecutionPolicy Bypass
,但我仍然想了解:为什么从 AHK 调用 PS 时我的 ExecutionPolicy 值不同?