您好,登錄后才能下訂單哦!
本來這篇文章應(yīng)該是上午就寫完的,結(jié)果,不得不承認(rèn)自己有點(diǎn)懶,對最近手頭上做的項(xiàng)目做了些總結(jié),Powershell開發(fā)運(yùn)維,也做了一段時(shí)間了,今天就來說說那些簡單的GUI的編程運(yùn)維,首先從彈出窗口說起吧。
彈出窗口就自己在寫PS GUI代碼是經(jīng)常用到的有3種方式,wscript方式,F(xiàn)orms方式,VB方式,先說說Wscript方式,這種方式最簡單,也最簡陋,只需要兩行代碼就可以簡單做出彈出窗口。
Wscript方式:
function Read-MessageBoxDialog
{
$PopUpWin = new-object -comobject wscript.shell
$PopUpWin.popup("Hello World")
}
Read-MessageBoxDialog
Forms方式,相對于Wscript方式來說,這種方式寫的代碼比較多但是呈現(xiàn)的樣式比較親切
function Read-MessageBoxDialog
{
param ([string]$Message,
[string]$WindowTitle,
[System.Windows.Forms.MessageBoxButtons]$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]$Icon = [System.Windows.Forms.MessageBoxIcon]::None)
Add-Type -AssemblyName System.Windows.Forms
return [System.Windows.Forms.MessageBox]::Show($Message, $WindowTitle, $Buttons, $Icon)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere" -Buttons OK -Icon Information
最后一種方式就是VB方式,這種方式是在PS中調(diào)用VB的方式來進(jìn)行彈出窗口,樣式與Forms基本類似
function Read-MessageBoxDialog
{
param ([string]$Message,[string]$WindowTitle)
Add-Type -AssemblyName Microsoft.VisualBasic
return [Microsoft.VisualBasic.Interaction]::MsgBox($Message,'Information',$WindowTitle)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere"
最后可以看出VB的樣式與Forms樣式一樣,但是代碼要比Forms的少很多,如果只是提示窗口,建議用VB形式,如果想讓提示窗口顯示為Information形式,并且OK與Cancel按鈕同時(shí)存在就將Forms方式中的Buttons屬性設(shè)置為 OKCancel
function Read-MessageBoxDialog
{
param ([string]$Message,
[string]$WindowTitle,
[System.Windows.Forms.MessageBoxButtons]$Buttons = [System.Windows.Forms.MessageBoxButtons]::OK,
[System.Windows.Forms.MessageBoxIcon]$Icon = [System.Windows.Forms.MessageBoxIcon]::None)
Add-Type -AssemblyName System.Windows.Forms
return [System.Windows.Forms.MessageBox]::Show($Message, $WindowTitle, $Buttons, $Icon)
}
Read-MessageBoxDialog -Message "Hello World" -WindowTitle "CustomTitleHere" -Buttons OKCancel -Icon Information
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。