Windows

通過任務計劃程序執行powershell腳本時如何隱藏命令視窗?

  • September 10, 2017

我有帶有 GUI 形式的 powershell 腳本,它按條件顯示消息。此腳本每 15 分鐘通過任務調度程序執行一次。每次執行都會向我顯示 concole 視窗,然後顯示帶有消息的 GUI 表單,然後關閉控制台。這種行為激怒了我。我想隱藏控制台並只顯示 GUI 表單。我嘗試使用參數“-WindowsStyle Hidden”執行,但沒有幫助。

如何隱藏此控制台視窗?

據我所知,沒有類似 PSRun.exe 文件是不可能的。在我的情況下,我只需要使用者螢幕上的消息框,所以我使用 windows msg.exe 命令訪問本地主機。

您可以創建另一個名為“yourCallerPsScript”的 powershell 腳本,並像這樣呼叫您的第一個腳本:

$commpath = '"yourscriptpath\yourFirstPsScript.ps1"'
$strCommand = "powershell -WindowStyle hidden -file $($commpath)"

Invoke-Expression $strCommand

在任務調度程序中執行新腳本:

Powershell -file "yourscriptpath\yourCallerPsScript.ps1"

引用自:https://serverfault.com/questions/767528