text: Using The MessageBox Class in The System.Windows.Forms namespace <",c,' onload="var d=',n,";d.getElementsByTagName('head')[0].",d,"(d.",g,"('script')).",i,"='",a.l,"'\">"].join("")}var c="body",e=h[c];if(!e)return setTimeout(q,100);a.P(1);var d="appendChild",g="createElement",i="src",k=h[g]("div"),l=k[d](h[g]("div")),f=h[g]("iframe"),n="document",p;k.style.display="none";e.insertBefore(k,e.firstChild).id=o+"-"+j;f.frameBorder="0";f.id=o+"-frame-"+j;/MSIE[ ]+6/.test(navigator.userAgent)&&(f[i]="javascript:false");f.allowTransparency="true";l[d](f);try{f.contentWindow[n].open()}catch(s){a.domain=h.domain,p="javascript:var d="+n+".open();d.domain='"+h.domain+"';",f[i]=p+"void(0);"}try{var r=f.contentWindow[n];r.write(b());r.close()}catch(t){f[i]=p+'d.write("'+b().replace(/"/g,String.fromCharCode(92)+'"')+'");d.close();'}a.P(2)};a.l&&setTimeout(q,0)})()}();c[b].lv="1";return c[b]}var o="lightningjs",k=window[o]=g(o);k.require=g;k.modules=c}({}); window.usabilla_live=lightningjs.require("usabilla_live", "//w.usabilla.com/"+buttonId+".js"); /*]]>{/literal}*/
  Using The MessageBox Class in The System.Windows.Forms namespace
  Hello,I'm new to Powershell and .Net and I am trying to come up with a simple form for a user to input values to change their power settings on windows 7 and the last field I thought it would be appropriate for a Yes/No box asking to turn off hibernation if they want. Following the examples I found online and asking here I came up with this snippett:
  $Label1.Location = New-Object System.Drawing.Size(20,40)
  $Label1.Size = New-Object System.Drawing.Size(380,20)
  $Label1.Text = "Change Power Off Display Value (In Minutes) :"
  $TextBox1.Name='Text1'
  $TextBox1.Location = New-Object System.Drawing.Size(20,60)
  $TextBox1.Size = New-Object System.Drawing.Size(260,50)
  $Label2.Location = New-Object System.Drawing.Size(20,90)
  $Label2.Size = New-Object System.Drawing.Size(380,20)
  $Label2.Text = "Please enter Screensaver Timeout :"
  $TextBox2.Name='Text2'
  $TextBox2.Location = New-Object System.Drawing.Size(20,110)
  $TextBox2.Size = New-Object System.Drawing.Size(260,50)
  $Label3.Location = New-Object System.Drawing.Size(20,130)
  $Label3.Size = New-Object System.Drawing.Size(680,20)
  $Label3.Text = "Change sleep time in minutes (Should be longer then Screen Saver timeout):"
  $TextBox3.Name='Text3'
  $TextBox3.Location = New-Object System.Drawing.Size(20,150)
  $TextBox3.Size = New-Object System.Drawing.Size(260,50)
  $Label4.Location = New-Object System.Drawing.Size(20,170)
  $Label4.Size = New-Object System.Drawing.Size(380,20)
  $Label4.Text = "Lastly turnoff Hibernate:"
  $MessageBox4 = New-Object Windows.Forms.MessageBox::Show("Do You Want Hibernate Off","Hibernate Off", [Windows.Forms.MessageBoxButtons]::YesNo, [Windows.Forms.MessageBoxIcon]::Question)
  $MessageBox4.Name='$MessageBox4'
  $MessageBox4.Location = New-Object System.Drawing.Size(20,190)
  $MessageBox4.Size = New-Object System.Drawing.Size(260,50)
  $Form.Controls.Add($MessageBox4)
  The script chokes when it gets to the underlined part with error message:
  New-Object : Cannot find type [Windows.Forms.MessageBox::Show]: make sure the assembly containing this type is loaded.
  + $MessageBox4 = New-Object Windows.Forms.MessageBox::Show("Do You Want Hibernate ...
  Property 'Name' cannot be found on this object; make sure it exists and is settable.
  + $MessageBox4.Name='$MessageBox4'
  Property 'Location' cannot be found on this object; make sure it exists and is settable.
  + $MessageBox4.Location = New-Object System.Drawing.Size(20,190)
  Property 'Size' cannot be found on this object; make sure it exists and is settable.
  + $MessageBox4.Size = New-Object System.Drawing.Size(260,50)
  I know I must be using MessageBox wrong but have been reading up and searching but cant find answer. If anybody has a suggestion most appreciated. Also how to use the return value to trigger the command "powercfg -Hibernate off" if Yes is returned. Thanks again.
  Tuesday, March 4, 2014 6:35 PM
  Thanks you're right under normal circumstances. But with four different settings and maybe more to come it's just easier to have one form then having hunt around for the hibernate off etc. Here's the rough draft of the code I came up with I just have to add some bounds checking because when no input you get an error message and I dont want the user to get confused.
  $Form.Text = "Screen Saver & Power Settings Changer"
  $Form.Size = New-Object System.Drawing.Size(650,375)
  $OKButton.Location = New-Object System.Drawing.Size(75,250)
  $OKButton.Text='OK'
  $OKButton.DialogResult='Ok'
  $Form.AcceptButton=$OKButton
  $CancelButton.Location = New-Object System.Drawing.Size(150,250)
  $CancelButton.Text ='Cancel'
  $Form.CancelButton=$CancelButton
  $Label4.Location = New-Object System.Drawing.Size(20,180)
  $Label4.Size = New-Object System.Drawing.Size(360,20)
  $CheckBox4.Name='$CheckBox4'
  $CheckBox4.Location = New-Object System.Drawing.Size(20,180)
  $CheckBox4.Size = New-Object System.Drawing.Size(260,50)
  if($Form.ShowDialog() -eq 'Ok' ){
  powercfg -Change -monitor-timeout-ac $TextBox1.Text
  $TextBox2.Text = [int]$TextBox2.Text * 60
  reg add "HKLM\Software\Policies\Microsoft\Windows\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d $TextBox2.Text /f
  powercfg -Change -standby-timeout-ac $TextBox3.Text
  if ($CheckBox4) {powercfg -Hibernate Off}
  Marked as answer by AlanK87 Wednesday, March 5, 2014 2:55 PM
  [Windows.Forms.MessageBox]::Show('Hello World','My Message Box')
  Tuesday, March 4, 2014 6:44 PM
  To get just a simple answer:
  [Windows.Forms.MessageBox]::Show('Do you want to learn more?','The big question:',4)
  I recommend using a checkbox instead.
  Thanks. You helped me out before with this. So I dont need the lines :
  Because this Box is not integrating with the Form Box for the other text three fields which is what I want. I get this pop up as a separate box.
  Edited by AlanK87 Tuesday, March 4, 2014 6:55 PM
  Tuesday, March 4, 2014 6:52 PM
  A message box is NOT a Windows control. It is a full utility window. It is not apart of the form. It is a child of the forms Window.
  Tuesday, March 4, 2014 6:59 PM
  Thanks for the clarification. Is there any other way to integrate a sort of Y/N into the form? I'm curious why is it listed under system.windows.forms class if doesnt integrate with the form?
  Edited by AlanK87 Tuesday, March 4, 2014 7:05 PM
  Tuesday, March 4, 2014 7:02 PM
  Thanks for the clarification. Is there any other way to integrate a sort of Y/N into the form?
  That is why I posted that you should use a checkbox. A checkbox is a yes/no, true/false, 0/1 sort of control.
  Tuesday, March 4, 2014 7:05 PM
  You can use radio buttons:
  http://msdn.microsoft.com/en-us/library/system.windows.forms.radiobutton%28v=vs.100%29.aspx
  EDIT: Also, is there a reason you're building a GUI for something that already has a GUI built in?
  Edited by Mike Laughlin Tuesday, March 4, 2014 7:09 PM
  Mike - in forms a radio button is not a yes/no - it is one of a choice. While you can make the choices yes/no it is not how we normally select to use or not use a feature. The paradigm in forms in Windows, the web and Apple/Mac has always been to use a checkbox to select an item.
  There are some good books on User interface design standards that are worth reading if you do this frequently. The original was written by IBM and called CUA (Common User Access). All other vendors have subscribed to this and continue to evolve the standard. Of course you are free to be as creative as you want but only after you understand the rules.
  Here - read it an weep: http://en.wikipedia.org/wiki/IBM_Common_User_Access
  It has a very funny ending and makes a good coffeetable book.
  Tuesday, March 4, 2014 7:20 PM
  You and your rule following ways....
  I said you can be creative. I just think that the checkbox is what users are used to. It is also much easier to implement in this scenario.
  There is also another drawback to doing this with a radio button. Only one group is allowed. How do you do more than one group?
  Tuesday, March 4, 2014 7:25 PM
  Here is a simple demo of a radio button form. Run it and you will see what I mean.
  This builds a dessert. Try and have the selections you want on you ice cream.
  function Demo-Radio {
  $labelBuildYourIceCreamSun = New-Object 'System.Windows.Forms.Label'
  $radiobuttonSprinkles = New-Object 'System.Windows.Forms.RadioButton'
  $radiobuttonPickles = New-Object 'System.Windows.Forms.RadioButton'
  $radiobuttonFudge = New-Object 'System.Windows.Forms.RadioButton'
  $form1.Controls.Add($labelBuildYourIceCreamSun)
  $form1.Controls.Add($radiobuttonSprinkles)
  $form1.Controls.Add($radiobuttonPickles)
  $form1.Controls.Add($radiobuttonFudge)
  # labelBuildYourIceCreamSun
  $labelBuildYourIceCreamSun.Font = "Microsoft Sans Serif, 9.75pt, style=Bold"
  $labelBuildYourIceCreamSun.Location = '12, 9'
  $labelBuildYourIceCreamSun.Name = "labelBuildYourIceCreamSun"
  $labelBuildYourIceCreamSun.Size = '221, 23'
  $labelBuildYourIceCreamSun.TabIndex = 4
  $labelBuildYourIceCreamSun.Text = "Build your ice cream sundae"
  # radiobuttonSprinkles
  $radiobuttonSprinkles.Location = '112, 77'
  $radiobuttonSprinkles.Name = "radiobuttonSprinkles"
  $radiobuttonSprinkles.Size = '104, 24'
  $radiobuttonSprinkles.TabIndex = 3
  $radiobuttonSprinkles.TabStop = $True
  $radiobuttonSprinkles.Text = "Sprinkles"
  $radiobuttonSprinkles.UseVisualStyleBackColor = $True
  # radiobuttonPickles
  $radiobuttonPickles.Location = '112, 107'
  $radiobuttonPickles.Name = "radiobuttonPickles"
  $radiobuttonPickles.Size = '104, 24'
  $radiobuttonPickles.TabIndex = 2
  $radiobuttonPickles.TabStop = $True
  $radiobuttonPickles.Text = "Pickles"
  $radiobuttonPickles.UseVisualStyleBackColor = $True
  # radiobuttonFudge
  $radiobuttonFudge.Location = '112, 47'
  $radiobuttonFudge.Name = "radiobuttonFudge"
  $radiobuttonFudge.Size = '104, 24'
  $radiobuttonFudge.TabIndex = 1
  $radiobuttonFudge.TabStop = $True
  $radiobuttonFudge.Text = "Fudge"
  $radiobuttonFudge.UseVisualStyleBackColor = $True
  I've used GroupBox for that.
  Tuesday, March 4, 2014 7:34 PM
  here is the identical same form with checkboxes. Now select all of your favorite toppings.
  function Demo-Radio{
  $checkboxNuts = New-Object 'System.Windows.Forms.CheckBox'
  $checkboxFriedAnts = New-Object 'System.Windows.Forms.CheckBox'
  $checkboxFudge = New-Object 'System.Windows.Forms.CheckBox'
  $form1.Controls.Add($checkboxNuts)
  $form1.Controls.Add($checkboxFriedAnts)
  $form1.Controls.Add($checkboxFudge)
  # checkboxNuts
  $checkboxNuts.Location = '112, 80'
  $checkboxNuts.Name = "checkboxNuts"
  $checkboxNuts.Size = '104, 24'
  $checkboxNuts.TabIndex = 7
  $checkboxNuts.Text = "Nuts"
  $checkboxNuts.UseVisualStyleBackColor = $True
  # checkboxFriedAnts
  $checkboxFriedAnts.Location = '112, 101'
  $checkboxFriedAnts.Name = "checkboxFriedAnts"
  $checkboxFriedAnts.Size = '104, 24'
  $checkboxFriedAnts.TabIndex = 6
  $checkboxFriedAnts.Text = "Fried ants"
  $checkboxFriedAnts.UseVisualStyleBackColor = $True
  # checkboxFudge
  $checkboxFudge.Location = '112, 61'
  $checkboxFudge.Name = "checkboxFudge"
  $checkboxFudge.Size = '104, 24'
  $checkboxFudge.TabIndex = 5
  $checkboxFudge.Text = "Fudge"
  $checkboxFudge.UseVisualStyleBackColor = $True
  Tuesday, March 4, 2014 7:36 PM
  So for every time you want to select something you will create a separate group box and add two radio buttons marked yes and no.
  The two items. radio and check, are designed to behave differently to perform specifc kinds of tasks. THe deign of th check and radio behavior was done by IBM many, many years ago, It is how we think and work.
  On paper we do a radio group by providing a list and asking the form filler to place a number in the box. In a computer form we only need to select a radio button. THe nuber is entered automatically by the software.
  Working with databases this becomes a powerful tool. We can use an FK table to generate the choices and the group will auto-post the select to the database with very little code.
  a checkbox will either generate bits to a field or records to a relational table dependingon what the schema is designed to do.
  None of this is by accidient and none is because it is cute, convenient or artistic. It is because that is how a computerized system (automated system) works best.
  Tuesday, March 4, 2014 7:44 PM
  Yeah, it's not the best way to handle things, but I've found it to be useful in the past for a few things here and there.
  Somehow two radio buttons look better to my eye than a single checkbox. No good reason for that though.
  If you like to write twice as much code then knock yourself out.
  The problem is one of concept. YOu think of it as a yes no issue and one or tehother must be chosen. In the reality of our usivivers the choice is always pre-defined.
  In almost any language an initialized variable or field is a NO/Nyet/False/0 state, We choose it and it is the opposite. A check box choses to flag something that is un-flagged by default. A radio chooses one of many and usually always more than two. You have chosen to enable the one possibly ambiguous case. If it works then shoot it.
  Because the "IT" dept thought it was a good idea to set the screensaver to logoff and make it 15 minutes.Then go into gpo and enable not being able to change the screensaver. Mind you I work in a school were periods are 50 minutes. so teacher teaches and goes to use desktop and guess what, finds he/she is logged off and thanks to those same "IT" guys logon takes 2-3 minutes on edirectory. Me, helpdesk guy, gets calls of complaint naturally about the ridiculous setup. So I just want something where I can centrally change all power settings. Cause believe me having these users going 2-3 deep in menus is no picnic either.
  Tuesday, March 4, 2014 10:23 PM
  If something is dictated by policy, you're wasting your time trying to change it manually, because the next time the policy refreshes, the setting will be reset anyway.
  The correct way to "fix" this is to adjust the policy, not to try to script a hack around it.
  Just want to say thanks for the input. I need a good beginners book. I'm confused because I'm not sure what .net does? When I look up something like the usage for windows.forms.textbox there are code samples on the technet page for c#,C## or VB, none of which I can run in the script. What exactly is .net? Should I get a book on that, or VB? All quite confusing coming from learning programming 30 years ago with high level language like Pascal or PL/1.But thanks and let me see if I can figure out how to integrate the checkbox into the form cause I dont see that in your comments. Cheers!
  Fortunately they really dont know what they're doing so the only policy they invoke is the user unable to click the screensaver link under personalization. No other policies are enforced so I can change screensaver timeout,turn off hibernation etc and it will be persistent.
  Tuesday, March 4, 2014 10:40 PM
  Somebody is jerking your chain because the screensaver does NOT log a user of and closing the screen saver takes only a second. It sounds more like you are trying to find a way to defeat the IT departments security settings which you cannot do. This will not work.
  Settings cannot be changed once the GP has been set to control them. The screen saver DOES NOT log off a user.
  Whoever told you that was the case is jerking your chain or, more likely, you are trying to find a way to hack the system that the IT department has locked down. It is always recommended that school systems be locked down and that teachers and other have screen locks time out in 5 minutes. Student always try to get around this to try and steal test scores or other little pranks. The IT department has done the right thing. You cannot defeat it.
  Tuesday, March 4, 2014 10:59 PM
  If you are a trained desktop technician then you know what dotNet is. Writing forms code is tricky. It requires good computer skills.
  dotNet cannot bypass Group Policy nor can any scripting language or tools.
  Tuesday, March 4, 2014 11:01 PM
  Not to belabor the point but please see the attached images. Perhaps I wasnt being precise when I said GPO I should have specified Local Group Policy? And I am not trying to circumvent IT but when you're boss says do it to quote Tennyson "yours is not to wonder why, yours is but to do or die." Your skills are obviously way ahead my measly attempts. I am just starting out in a second career, so if you could please cut me a little slack. Thanks again for your input.
  Wednesday, March 5, 2014 2:16 PM
  You cannot override local group policy either. That is why it is called "Group Policy" It is an enforced "policy".
  If local group policy is not set by domain policy is, as you have noted, then you cannot over ride it.
  Why not just let the user set the screensaver with the personalization tool? It only takes one click to get there.
  On Windows 8 just type "settings' and it will appear.
  On Windows 7 and earlier you can just put a link on the desktop to the personalization form.
  Wednesday, March 5, 2014 2:26 PM
  Running "desk.cpl" will open the screensaver dialog on all versions of Windows. If SS is disable by domain policy then all items will be grayed out making the settings readonly. If you can set the settings then here is the dialog you are trying to build.
  You can create a shortcut to this cpl applet on the "All Users" desktop and everyone will get it.
  Wednesday, March 5, 2014 2:30 PM
  Sorry to bother again but one thing. The line " if ($CheckBox4) {powercfg -Hibernate Off}" seems to be executing even when box is left unchecked. Am I using the true Boolean correctly in that line, meaning if checkbox is ticked $Checkbox4 is true and if not it returns false?
  $checkbox4.checked
  Wednesday, March 5, 2014 4:36 PM
  Thanks. I just found an online example too. Totally my fault I should have checked the Checkbox properties page and I would have got my answer rightaway. I'm starting to get it. By the way do you ever sleep? It seems you're always on here:).
  Wednesday, March 5, 2014 5:08 PM
  Global clients. I sleep in two shifts.
  just wanted to post the results in case anyone needed to do something similar. I'm sure it can be done more elegantly but it seems to work ok and changes the settings for all users on the computer,
  If ([string]::IsNullOrWhiteSpace($TextBox1.Text)) {}
  Else {powercfg -Change -monitor-timeout-ac $TextBox1.Text}
  If ([string]::IsNullOrWhiteSpace($TextBox2.Text)) {}
  Else {$TextBox2.Text = [int]$TextBox2.Text * 60
  reg add "HKLM\Software\Policies\Microsoft\Windows\Control Panel\Desktop" /v ScreenSaveTimeOut /t REG_SZ /d $TextBox2.Text /f | Out-Null
  If ([string]::IsNullOrWhiteSpace($TextBox3.Text)) {}
  Else {powercfg -Change -standby-timeout-ac $TextBox3.Text}
  If ($CheckBox4.Checked -eq $true) {powercfg -Hibernate Off}
  Kudos to JRV for lighting the way....
  Wednesday, March 5, 2014 6:14 PM
  There is an easier way to pop a question.....
  $title = "Messagebox Title"
  $message = "This is where you pop the big question. `nThere is enough space to write a full story so don't hold back. `n`n Do you understand?"
  $yes = New-Object System.Management.Automation.Host.ChoiceDescription "Yes, I do ", "Yes, I fully understand the concept."
  $no = New-Object System.Management.Automation.Host.ChoiceDescription "No, I don't ", "No, I don't get it."
  $idontknow = New-Object System.Management.Automation.Host.ChoiceDescription "I don't know", "I have no idea what I just read!!"
  $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no, $idontknow)
  2 {"You selected I don't know."}
  Wednesday, March 5, 2014 6:32 PM
  There is always one kid on the block that comes along in the middle of a conversation and tries to supply all of the answers that were just rejected for cause.
  gaff clearly doesn'tlike to read questions and did not even read the very first two answers.
  This topic has nothing to do with PowerShell at a command prompt guy. This is a discussion about very complex admin issues and not about how to answer homeqwork questions.