[英]How do I execute a powershell script by a shortcut key?
So I have successfully bound a key to open this script:所以我已经成功绑定了一个密钥来打开这个脚本:
But the way to run that script with PowerShell is to right-click it and go Open with PowerShell
.但是使用 PowerShell 运行该脚本的方法是右键单击它并 go
Open with PowerShell
。 Using the key binding, it just opens it normally (so with notepad).使用键绑定,它只是正常打开它(所以用记事本)。
How can I make it so it opens with PowerShell from that binding?我怎样才能使它从该绑定中以 PowerShell 打开?
You already have a lnk
that points to your script file.您已经有一个指向您的脚本文件的
lnk
。 Make that point to PowerShell and pass your file as a parameter.将其指向 PowerShell 并将您的文件作为参数传递。 Assuming your file is located in
C:\PSScripts
you would have to set the Target of the lnk
to假设您的文件位于
C:\PSScripts
中,您必须将lnk
的目标设置为
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& C:\PSScripts\Display Off.ps1" -NoLogo -NonInteractive -NoProfile
So, you can't run PS script, because security feature.所以,你不能运行 PS 脚本,因为安全特性。 User can't double click it.
用户不能双击它。 You can create simple.bat like:
您可以像这样创建 simple.bat:
powershell -command Set-ExecutionPolicy RemoteSigned
powershell -command Your Script
powershell -command Set-ExecutionPolicy Restricted
Check too this topic: Is there a way to make a PowerShell script work by double clicking a.ps1 file?检查这个主题: 有没有办法通过双击 a.ps1 文件来使 PowerShell 脚本工作? There are more solutions there.
那里有更多的解决方案。
Go to the General
tab in your shortcut settings, and change the Open with
row from notepad
to Go 到快捷方式设置中的
General
选项卡,然后将Open with
从notepad
更改为
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.