Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Several ways of Powershell pop-up window

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Originally, this article was supposed to be finished in the morning, but as a result, I had to admit that I was a little lazy and made some summary of the recent projects at hand. Powershell development, operation and maintenance has also been done for a period of time. Today, let's talk about those simple GUI programming operations and maintenance. Let's start with the pop-up window.

Pop-up window to write their own PS GUI code is often used in three ways, wscript mode, Forms way, VB way, first talk about Wscript way, this way is the simplest, but also the most crude, only two lines of code can simply make a pop-up window.

Wscript mode:

Function Read-MessageBoxDialog

{

$PopUpWin = new-object-comobject wscript.shell

$PopUpWin.popup ("Hello World")

}

Read-MessageBoxDialog

Forms way, compared with Wscript way, this way writes more code, but presents a more friendly style.

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

The last way is VB, which calls VB in PS to make pop-up windows, which is basically similar to 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"

Finally, we can see that the style of VB is the same as that of Forms, but the code is much less than that of Forms. If it is just a prompt window, it is recommended to use VB form. If you want the prompt window to be displayed in Information form, and the OK and Cancel buttons exist at the same time, set the Buttons property in Forms mode to 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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report