M. Simon
M. Simon

Reputation: 111

How do I create a popup window with Yes/No buttons and a Information Mark icon?

I need to have a popup window in PowerShell that has the information mark icon with yes & no buttons.

My current code is as follows:

$wshell = New-Object -ComObject Wscript.Shell
  $answer = $wshell.Popup("Do you want to continue?",0,"Alert",0x4)

if($answer -eq 7){exit}

With only the yes or no part. I need an icon there too.

Upvotes: 7

Views: 22638

Answers (2)

postanote
postanote

Reputation: 16086

Tagging on to samgak. There are a number of ways to do what you are after.

Or this...

[System.Windows.Forms.MessageBox]::Show("We are proceeding with next step." , "Status" , 4, 64)

Or this...

[System.Windows.Forms.MessageBox]::Show("Continue Task?","What a Mess", "YesNo" , "Information" , "Button1")

Or this...

[void][System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) 
# [microsoft.visualbasic.interaction]::Msgbox($message,"$button,$icon",$title)
[Microsoft.VisualBasic.Interaction]::MsgBox(“Do you agree?”, ‘YesNoCancel,Information’, “Respond please”) 

Upvotes: 6

samgak
samgak

Reputation: 24417

You can do it like this:

$answer = $wshell.Popup("Do you want to continue?",0,"Alert",64+4)

The values for the icons are as follows:

Stop          16
Question      32
Exclamation   48
Information   64

The values for the buttons are as follows:

OK               0
OKCancel         1
AbortRetryIgnore 2
YesNoCancel      3
YesNo            4
RetryCancel      5

So information icon and yes/no buttons is 64 + 4

IMO in this situation it makes more sense to use a question icon since you are asking a question rather than just conveying information so it would be 32 + 4 in that case.

Upvotes: 16

Related Questions