簡體   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