What's new
Carbonite

South Africa's Top Online Tech Classifieds!
Register a free account today to become a member! (No Under 18's)
Home of C.U.D.

Message Box with Custom Buttons - Powershell

Avi_R

Epic Member
Rating - 100%
26   0   0
Joined
Sep 27, 2015
Messages
58
Reaction score
9
Points
3,535
Location
Western Cape
Hi Guys,

I am trying to get a MessageBox to pop up in powershell, but instead of the default windows buttons, I wanted to know if i can change the buttons, and depends on what the user clicks, that value must be loaded into a variable.

eg.

[System.Windows.Forms.MessageBox]::Show("Which planet do we want to visit today?" , "Status" , 4)

this will bring up a message box with yes or no. I wan the button to say mars or venus.

Thank you guys in advance for any assistance.
 

Attachments

  • 2018-05-29_10-33-36.png
    2018-05-29_10-33-36.png
    2.8 KB · Views: 2
So to place the result into a variable is quite easy it seems
Code:
$msgBoxInput =  [System.Windows.MessageBox]::Show('Would you like to play a game?','Game  input','YesNoCancel','Error')

switch  ($msgBoxInput) {

  'Yes' {

  ## Do something

  }

  'No' {

  ## Do something

  }

  'Cancel' {

  ## Do something

  }

  }

Now for changing the text of the button, I assume you would need to target the buttons class and run a setText kind of function.

Are you able to target the buttons?

I'm not really a powershell dev
 
Have a look at this link The MessageBox Control

It says there is a MessageBoxButtons Object that you can create to customise the Buttons. You then just pass this to your MessageBox show method like such:

Code:
[System.Windows.Forms.MessageBox]::Show('text', 'title', MessageBoxButtons)

Let me know if this helps :)
 
@Zeedinstein Thanks for the links bro. I see there are core classes that you can edit to get custom button titles. Unfortunately I don't have the time to go edit the classes. So i went the poor devs route and created an inline console menu :)

But those links are rather interesting. Will give it a shout. The code i am writing is for auto site fail over for a rather technical client so GUI's are optional lol.
 

Users who are viewing this thread

Latest posts

Back
Top Bottom