【发布时间】:2019-11-04 21:02:56
【问题描述】:
我有一个简单的自动热键脚本
!+l:: RunWait, PowerShell -NoExit -C "Import-Module D:\projects\changescreensaver\changescreensaver.psm1; Set-ScreenSaverTimeout 1;"
但它不会让我加载我的 ps 配置文件或执行导入模块并给我一个执行策略错误:
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 值不同?
【问题讨论】:
-
不,但我意识到 AHK 运行的是 32 位的 powershell,而我的终端是 64 位的,所以我想这就是问题所在。
标签: powershell autohotkey executionpolicy