header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Powershell Forms
Last Post 26 Aug 2010 04:05 PM by Josh. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
JoshUser is Offline
New Member
New Member
Posts:4
Avatar

--
26 Aug 2010 09:36 AM
    I am trying to use a form with Powershell that utilizes check-boxes. I have the form working, but I am not quite sure how to write the code for the check-box. For example: I have a check-box that a user can select or deselect, and I have a run button at the bottom, what I want to do is have two options. If the user checks the check-box and hits run do option 1, if the user leaves the check-box unselected do option 2.  
    Marco Shaw (MVP)User is Offline
    Veteran Member
    Veteran Member
    Posts:1642
    Avatar

    --
    26 Aug 2010 09:41 AM
    Please share what code you have up to now.
    Marco

    *Microsoft MVP - Windows PowerShell
    https://mvp.support.microsoft.com/profile/Marco.Shaw
    *Co-Author - Sams Windows PowerShell Unleashed 2nd Edition
    *Blog - http://marcoshaw.blogspot.com
    JoshUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    26 Aug 2010 09:50 AM
    I just have the form code, Which is quite large. I will post a snippet of it.

    Sample Generated By Primal Forms:

    #Generated Form Function
    function GenerateForm {

    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    #endregion

    #region Generated Form Objects
    $form1 = New-Object System.Windows.Forms.Form
    $button1 = New-Object System.Windows.Forms.Button
    $checkBox1 = New-Object System.Windows.Forms.CheckBox
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    #endregion Generated Form Objects

    #----------------------------------------------
    #Generated Event Script Blocks
    #----------------------------------------------
    #Provide Custom Code for events specified in PrimalForms.
    $button1_OnClick=
    {
    #TODO: Place custom script here

    }

    $OnLoadForm_StateCorrection=
    {#Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
    }

    #----------------------------------------------
    #region Generated Form Code
    $form1.Text = "Primal Form"
    $form1.Name = "form1"
    $form1.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 877
    $System_Drawing_Size.Height = 642
    $form1.ClientSize = $System_Drawing_Size

    $button1.TabIndex = 1
    $button1.Name = "button1"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 145
    $System_Drawing_Size.Height = 37
    $button1.Size = $System_Drawing_Size
    $button1.UseVisualStyleBackColor = $True

    $button1.Text = "button1"

    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 18
    $System_Drawing_Point.Y = 503
    $button1.Location = $System_Drawing_Point
    $button1.DataBindings.DefaultDataSourceUpdateMode = 0
    $button1.add_Click($button1_OnClick)

    $form1.Controls.Add($button1)


    $checkBox1.UseVisualStyleBackColor = $True
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Width = 286
    $System_Drawing_Size.Height = 54
    $checkBox1.Size = $System_Drawing_Size
    $checkBox1.TabIndex = 0
    $checkBox1.Text = "checkBox1"
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 18
    $System_Drawing_Point.Y = 26
    $checkBox1.Location = $System_Drawing_Point
    $checkBox1.DataBindings.DefaultDataSourceUpdateMode = 0
    $checkBox1.Name = "checkBox1"


    $form1.Controls.Add($checkBox1)

    #endregion Generated Form Code

    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($OnLoadForm_StateCorrection)
    #Show the Form
    $form1.ShowDialog()| Out-Null

    } #End Function

    #Call the Function
    GenerateForm


    A sample of the custom code that I want the check-box to run is:

    $LocalAdministrator = $(Get-WmiObject –Query ‘Select * from Win32_UserAccount
    Where (LocalAccount="True" and SID like "%-500")’)
    $LocalAdministrator.Disabled = $True
    $LocalAdministrator.Put()



    JoshUser is Offline
    New Member
    New Member
    Posts:4
    Avatar

    --
    26 Aug 2010 04:05 PM
    I figured it out here is what I did:

    I added CheckState property to the actual checkbox properties.

    if($DisableAdmin.CheckState -eq "1") {$LocalAdministrator = $(Get-WmiObject –Query ‘Select * from Win32_UserAccount
    Where (LocalAccount="True" and SID like "%-500")’)
    $LocalAdministrator.Disabled = $True
    $LocalAdministrator.Put()
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer