溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Powershell彈出窗口的幾種方式

發(fā)布時(shí)間:2020-07-10 17:19:01 來源:網(wǎng)絡(luò) 閱讀:3826 作者:azrael0328 欄目:系統(tǒng)運(yùn)維

本來這篇文章應(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

Powershell彈出窗口的幾種方式


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

Powershell彈出窗口的幾種方式


最后一種方式就是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"

Powershell彈出窗口的幾種方式


最后可以看出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

Powershell彈出窗口的幾種方式







向AI問一下細(xì)節(jié)

免責(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)容。

AI