-->

Launch powershell script with keyboard hotkey

2020-04-07 19:07发布

问题:

I want to execute a powershell script (ps1-file) with a hotkey on my keyboard (CTRL + SHIFT + F for instance).

I managed to create a shortcut of the script (right click in explorer > new > shortcut). The shortcut's target is: "%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "PATH_TO_THE_SCRIPT" ".

When I execute the script manually (by double-clicking the shortcut), it works like a charm. But when I try to assign a "Shortcut key" in the Shortcut Properties (CTRL + SHIFT + F) and press the shortcut key I just defined, nothing happens. What's the matter?

I'm quite sure it has something to do with security policies. But I don't know what exactly it is.

This is my Execution-Policy:

Scope ExecutionPolicy
----- ---------------
MachinePolicy  Undefined
UserPolicy     Undefined
Process        RemoteSigned
CurrentUser    Unrestricted
LocalMachine   Unrestricted

Any help is appreciated.

回答1:

That's it. As soon as I move the shortcut file to the desktop and redefine the "shortcut key", the shortcut key works!

Is there a particular reason, why the shortcut has to be on the desktop?



回答2:

Fist start PowerShell with run as administrator . then type this command on it :

Set-ExecutionPolicy Bypass -Force

after this you can run all script.

remember if you use Powershell_ise (IDE for powershell) don't use 86x when you're OS is 64 bit.and if you're directory in desktop you should fist set you're directory with :

cd "enter desktop directory"