繁体   English   中英

如何通过快捷键执行 powershell 脚本?

[英]How do I execute a powershell script by a shortcut key?

所以我已经成功绑定了一个密钥来打开这个脚本:

快捷方式设置

但是使用 PowerShell 运行该脚本的方法是右键单击它并 go Open with PowerShell 使用键绑定,它只是正常打开它(所以用记事本)。

我怎样才能使它从该绑定中以 PowerShell 打开?

您已经有一个指向您的脚本文件的lnk 将其指向 PowerShell 并将您的文件作为参数传递。 假设您的文件位于C:\PSScripts中,您必须将lnk的目标设置为

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& C:\PSScripts\Display Off.ps1" -NoLogo -NonInteractive -NoProfile

在此处输入图像描述

所以,你不能运行 PS 脚本,因为安全特性。 用户不能双击它。 您可以像这样创建 simple.bat:

powershell -command Set-ExecutionPolicy RemoteSigned 
powershell -command Your Script
powershell -command Set-ExecutionPolicy Restricted

检查这个主题: 有没有办法通过双击 a.ps1 文件来使 PowerShell 脚本工作? 那里有更多的解决方案。

Go 到快捷方式设置中的General选项卡,然后将Open withnotepad更改为

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM