Page 1 of 1

Confirmation box?

Posted: Mon Mar 04, 2013 11:50 am
by bheidemann
How could I make a simple confirmation box? I have an action tied to a button but I would like the user to confirm the action before it takes place. Thank you

Re: Confirmation box?

Posted: Mon Mar 04, 2013 12:07 pm
by davidc
You can use the messagebox:
PowerShell Code
Double-click the code block to select all.
if([System.Windows.Forms.MessageBox]::Show(\"Text\",\"Caption\") -eq \'OK\')
{
	#run script
}
PrimalForms 2011 & PowerShell Studio 2012 have a snippet called \"msgbox\" you can use.

David

Re: Confirmation box?

Posted: Mon Mar 04, 2013 12:13 pm
by bheidemann
Where can I get more info on the message box? I like your example but there isn\'t a way for the user to cancel out of it.

Re: Confirmation box?

Posted: Tue Mar 05, 2013 10:09 am
by davidc
One of the inputs to the message box allows you to specify the buttons to display:
PowerShell Code
Double-click the code block to select all.
if([System.Windows.Forms.MessageBox]::Show("Continue?", "Question",[System.Windows.Forms.MessageBoxButtons]::OKCancel) -eq "OK")
{
	Write-Host "OK!"
}
Here is the MSDN help for the messagebox:

http://msdn.microsoft.com/en-us/library ... .Show.aspx

David