茫茫網海中的冷日 - 對這文章發表回應
茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1673176 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00332.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

對這文章發表回應

發表限制: 非會員 可以發表

發表者: 冷日 發表時間: 2016/2/20 4:34:59
#28 : Display Messagebox with Powershell
Although, I never came accross such a situation where I need to throw a messagebox. But, just as I was playing, I tried to throw messagebox from Powershell.

Generating a Messagebox -

1. Load the Assembly
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

Output-
GAC Version Location
--- ------- --------
True v2.0.50727 C:\Windows\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll

Note: If you don't want the output, you can simple redirect to Out-nul. This will skip displaying assembly loading statement.

2. Display a simple Messagebox
[System.Windows.Forms.MessageBox]::Show("We are proceeding with next step.")

Now, the messagebox appears something like this -


If you see above message, you will find Title is missing. Let's add a title also by adding below piece of code -
[System.Windows.Forms.MessageBox]::Show("We are proceeding with next step." , "Status")



So, this was all about showing message with title. This was just OK message so, there is nothing to decide for user except pressing OK button.
Types of Messageboxes :
We have 6 types of Messageboxes in Powershell -
0: 	OK
1: 	OK Cancel
2: 	Abort Retry Ignore
3: 	Yes No Cancel
4: 	Yes No
5: 	Retry Cancel

Note: The number mentioned in left is the third parameter of Messagebox.

If you want to show Yes No, just add 4 as third parameter -
[System.Windows.Forms.MessageBox]::Show("We are proceeding with next step." , "Status" , 4)

Now, this will display a Messagebox like this -


How to get values from Messagebox?
As you know, when you press any button, you need to get the result and work upon the decision -
$OUTPUT= [System.Windows.Forms.MessageBox]::Show("We are proceeding with next step." , "Status" , 4)
if ($OUTPUT -eq "YES" )
{
..do something

}
else
{
..do something else
}

The value of button pressed is stored in $OUTPUT variable. This variable can then be used for your programming logic.

I have given just a primer how to use Messagebox class. But, if you want to go indepth of System.Windows.Forms.MessageBox class, you may look for the link below -

http://msdn.microsoft.com/en-us/library/system.windows.forms.messageboxbuttons.aspx

原文出處:
Som's Powershell Tips: #28 : Display Messagebox with Powershell
內容圖示
url email imgsrc image code quote
樣本
bold italic underline linethrough   












 [詳情...]
validation picture

注意事項:
預覽不需輸入認證碼,僅真正發送文章時才會檢查驗證碼。
認證碼有效期10分鐘,若輸入資料超過10分鐘,請您備份內容後,重新整理本頁並貼回您的內容,再輸入驗證碼送出。

選項

Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|