我正在努力尋找答案,這可能意味著我問錯了問題。
我寫了一個有彈出視窗的 PS1 腳本,一切都很好!我使用了這種方法:
$msgBoxInput = [System.Windows.MessageBox]::Show("You are about to publish Part $UserPart1, would you like to coninue?",'Confirm Update','YesNo')switch ($msgBoxInput)
{
'Yes'
{
Runs Code
}
'No'
{
Return
}
}
那作業得很好。直到我使用批處理檔案啟動 PS1。
這是我用來運行批處理檔案的代碼:
Powershell.exe -executionpolicy remotesigned -windowstyle hidden -File "C:\Updater 2.0.ps1"
批處理檔案有效,但彈出視窗不會發生。
所以我換了檔,嘗試使用這樣的彈出視窗:
$msgBoxInput = [System.Windows.MessageBox]::Show("You are about to publish Part $UserPart1, would you like to coninue?",'Confirm Update','YesNo')
再一次,訊息框沒有彈出。如果我洗掉訊息開頭的“$msgBoxInput =”,則會彈出該框,但無論用戶選擇什么,代碼都會像按下“是”一樣運行。
這可能是完全錯誤的方法,我真的不知道。我一直為我的用戶組(我有 30 多個用戶)使用批處理檔案,因為它比嘗試使用實際的 PS1 更容易。如果有更好/更簡單的路線,我會全力以赴!
這是我使用 PS1 的第一個表單,所以我也可能做錯了。
謝謝大家的幫助。
uj5u.com熱心網友回復:

Powershell.exe -executionpolicy remotesigned -File D:\PShell\SO\72366658.ps1
Runs Code
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/482010.html
