Windows Vista Forums

Using Radio Buttons within Powershell

  1. #1


    Stuart.B Guest

    Using Radio Buttons within Powershell

    Hi,

    Could anyone help me out with the following problem?

    I'm currently using Window's Powershell to create an installation script,
    and have come across 2 problems.

    The first problem is that I have to processes which happen at the same time,
    but I want one to happen first, then once that one has completed I want the
    next one to happen. The part of the script for this which I'm having a
    problem with is the following.

    #Region Main code

    updatelog "Beginning installation of $strProductName"

    logfilecheck

    filecheck $strCommand # Check that file exits

    if ($strCommand -gt 0) {
    startinstall $strCommand $strArg # first parameter is the executable, the
    second is the arguments. ALL arguments must be in the second parameter
    }

    Stop-PSJob -Name $form "Flex Domain Name"

    #show Form
    $form.Add_Shown({
    $script:dt = (&$scriptBlock | out-dataTable)
    $scriptG.DataSource = $DT.psObject.baseobject
    $Rows.Text="[Rows:$($script:dt.rows.count)]"
    $dg.AutoResizeColumns()
    $form.Activate()
    })



    $form.showdialog()
    }

    The next problem I have is that I'm trying to use Radio Buttons to select
    which .reg file the installation should use depending on which domain I'm in.
    The only problem I have is getting the radio buttons to help the installation
    detect which .reg file it should use. What type of Event Handler/Argument
    should I use so that it picks up the correct .reg file? If anyone has any
    ideas, or example scripts please let me know.

    Many Thanks.

      My System SpecsSystem Spec

  2. #2


    Marco Shaw [MVP] Guest

    Re: Using Radio Buttons within Powershell

    Stuart.B wrote:

    > Hi,
    >
    > Could anyone help me out with the following problem?
    >
    > I'm currently using Window's Powershell to create an installation script,
    > and have come across 2 problems.
    >
    > The first problem is that I have to processes which happen at the same time,
    > but I want one to happen first, then once that one has completed I want the
    > next one to happen. The part of the script for this which I'm having a
    > problem with is the following.
    Try tagging just "|out-null" at the end of the commands that you want to
    wait for them to complete.

    I've not tried your WinForms code yet...

    Marco

      My System SpecsSystem Spec

  3. #3


    Marco Shaw [MVP] Guest

    Re: Using Radio Buttons within Powershell


    > #show Form
    > $form.Add_Shown({
    > $script:dt = (&$scriptBlock | out-dataTable)
    > $scriptG.DataSource = $DT.psObject.baseobject
    > $Rows.Text="[Rows:$($script:dt.rows.count)]"
    > $dg.AutoResizeColumns()
    > $form.Activate()
    > })
    >
    > $form.showdialog()
    > }
    Can you share your entire code or is that a problem?

    Marco

      My System SpecsSystem Spec

  4. #4


    Stuart.B Guest

    Re: Using Radio Buttons within Powershell



    "Marco Shaw [MVP]" wrote:

    >

    > > #show Form
    > > $form.Add_Shown({
    > > $script:dt = (&$scriptBlock | out-dataTable)
    > > $scriptG.DataSource = $DT.psObject.baseobject
    > > $Rows.Text="[Rows:$($script:dt.rows.count)]"
    > > $dg.AutoResizeColumns()
    > > $form.Activate()
    > > })
    > >
    > > $form.showdialog()
    > > }
    >
    > Can you share your entire code or is that a problem?
    >
    > Marco
    >
    No, not a problem. I have replaced certain parts of the code, as it's work
    related and I'm not allowed to disclose that information. I've tried to
    |Out-Null way and it doesn't seem to have an effect. Any suggestions???

    Here is the entire script.

    #region variables

    $erroractionpreference = "SilentlyContinue"

    $strComputer = (Get-Content env:COMPUTERNAME) # Store computer name

    $root = [ADSI]"LDAP://RootDSE" #
    $strDomain = $root.Get("rootDomainNamingContext") # Connect to Active
    Directory

    $strInsPath = pwd # Store local working directory

    $strLogDetails = "Started main installation routine"

    ##################################################################################
    ##################################################################################
    # Start of engineer editable variables
    #

    $strProductName = "Application Name"

    $strCommand = cd "d:\Application"

    $strArg = msiexec /i "Application.msi"

    # End of engineer editable variables
    #
    ##################################################################################
    ##################################################################################

    $strLogFile = "Log File Location"

    $strOldLogFile = "Old Log File Location"

    #endregion

    #region functions

    # load WinForms
    [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

    # create form
    $form = New-Object Windows.Forms.Form
    $form.text = "Form Name"
    $form.top = 10
    $form.left = 10
    $form.height = 130
    $form.width = 275

    # create label
    $label = New-Object Windows.Forms.Label
    $label.text = "Domain Name"
    $label.height = 30
    $label.width = 75
    $label.top = 2
    $label.left = 25
    $form.controls.add($label)

    # create button
    $button = New-Object Windows.Forms.Button
    $button.add_click({onPress})
    $button.text = "OK"
    $button.height = 20
    $button.width = 50
    $button.top = 60
    $button.left = 100
    $form.controls.add($button)

    # create radiobutton
    $RadioButton = New-Object Windows.Forms.radiobutton
    $RadioButton.text = "Button Text"
    $RadioButton.height = 20
    $RadioButton.width = 150
    $RadioButton.top = 2
    $RadioButton.left = 100
    $form.controls.add($RadioButton)


    # create radiobutton1
    $radiobutton1 = New-Object Windows.Forms.radiobutton
    $RadioButton1.text = "Button Text"
    $RadioButton1.height = 20
    $RadioButton1.width = 150
    $RadioButton1.top = 30
    $RadioButton1.left =100
    $form.controls.add($RadioButton1)

    # create event handler for button
    $event = {
    $form.Close()
    }

    # attach event handler
    $button.Add_Click($event)

    # attach controls to form
    $form.controls.add($button)
    $form.controls.add($label)
    $form.controls.add($textbox)

    $form.showdialog()

    function filecheck {

    param ($chkpath)

    if ((Test-Path $chkpath) -eq $false) {

    updatelog "$chkpath NOT FOUND!!!"

    finish 1

    }

    }


    function logfilecheck {
    if ((Test-Path $strLogFile) -eq $true) {

    if ((Test-Path $strOldLogFile) -eq $false) {

    md $strOldLogFile

    }

    Move-Item -force $strLogFile LogFileName.log

    }

    }



    function finish { # finishes the script and outputs an appropriate message

    param ($iserror)

    if ($iserror -eq 1)

    {
    $Date = Get-Date

    cls

    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
    "***ERROR: Installation aborted! $Date" >> $strLogFile
    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile

    exit 1 # returns $False to indicate error if needed

    }

    else

    {

    $Date = Get-Date

    cls

    $host.ui.rawui.windowtitle = "Installation Finished."

    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile
    "***INFO: Installation completed successfully! $Date" >> $strLogFile
    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" >> $strLogFile

    exit 1
    }

    function errorcheck {

    ###################################################################################
    # This function checks for errors in the previous command and the logfile
    entry #
    # is updated
    #
    ###################################################################################

    if (!$?) {

    updatelog "$Error.ErrorDetails"

    finish 1

    }

    }

    function updatelog {

    ###################################################################################
    # This function updates the install log
    #
    ###################################################################################

    param($strLogMessage)

    $strdate = date

    $strMessage = "$strdate" + " " + "$strLogMessage"

    $strMessage >> $strLogFile

    }

    function startinstall {

    ###################################################################################
    # This function runs the installation command line
    #
    ###################################################################################

    param($strCommand ,$strArg)

    updatelog "Executing $strCommand"

    #cd ..

    #$strCommand = "$strInsPath" + "\" + "$strExeFile" # Concatenate full path
    to installation executable

    $shell = New-Object -comObject Shell.Application #

    $shell.ShellExecute("$strCommand","$strArg") # Running installation program

    errorcheck

    updatelog "$strCommand has been executed"

    }

    #endregion



    #region Constructor

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

    [void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

    #endregion

    #Region Main code

    updatelog "Beginning installation of $strProductName"

    logfilecheck

    filecheck $strCommand # Check that file exits

    if ($strCommand -gt 0) {
    startinstall $strCommand $strArg
    }

    #show Form
    $form.Add_Shown({
    $script:dt = (&$scriptBlock | out-dataTable)
    $scriptG.DataSource = $DT.psObject.baseobject
    $Rows.Text="[Rows:$($script:dt.rows.count)]"
    $dg.AutoResizeColumns()
    $form.Activate()
    })

    $form.showdialog() | Out-Null
    }

    $add = $doc.getElementByID("RadioButton")
    $add = $doc.getElementByID("RadioButton1")

    $add.checked = $true

    finish 0
    #endregion



      My System SpecsSystem Spec

  5. #5


    Stuart.B Guest

    Re: Using Radio Buttons within Powershell

    Marco,

    I've just managed to get the Out-Null command to work within the script now.
    So that is not an issue.

    "Marco Shaw [MVP]" wrote:

    > Stuart.B wrote:

    > > Hi,
    > >
    > > Could anyone help me out with the following problem?
    > >
    > > I'm currently using Window's Powershell to create an installation script,
    > > and have come across 2 problems.
    > >
    > > The first problem is that I have to processes which happen at the same time,
    > > but I want one to happen first, then once that one has completed I want the
    > > next one to happen. The part of the script for this which I'm having a
    > > problem with is the following.
    >
    > Try tagging just "|out-null" at the end of the commands that you want to
    > wait for them to complete.
    >
    > I've not tried your WinForms code yet...
    >
    > Marco
    >

      My System SpecsSystem Spec

  6. #6


    Marco Shaw [MVP] Guest

    Re: Using Radio Buttons within Powershell


    > No, not a problem. I have replaced certain parts of the code, as it's work
    > related and I'm not allowed to disclose that information. I've tried to
    > |Out-Null way and it doesn't seem to have an effect. Any suggestions???
    You mentioned stop-psjob in your first post. Are you using PSH v1 or
    PSH v2 CTP?

    For v1, I'm going to check out whether you can background a regular DOS
    command with this:
    http://jtruher.spaces.live.com/blog/...628D!130.entry

    The only other thing I can think of if having your EXEs write out to
    files when they are done, and have the PowerShell script loop until a
    certain log entry or file is present, then continue.

    Marco

      My System SpecsSystem Spec

  7. #7


    Stuart.B Guest

    Re: Using Radio Buttons within Powershell



    "Marco Shaw [MVP]" wrote:

    >

    > > No, not a problem. I have replaced certain parts of the code, as it's work
    > > related and I'm not allowed to disclose that information. I've tried to
    > > |Out-Null way and it doesn't seem to have an effect. Any suggestions???
    >
    > You mentioned stop-psjob in your first post. Are you using PSH v1 or
    > PSH v2 CTP?
    >
    > For v1, I'm going to check out whether you can background a regular DOS
    > command with this:
    > http://jtruher.spaces.live.com/blog/...628D!130.entry
    >
    > The only other thing I can think of if having your EXEs write out to
    > files when they are done, and have the PowerShell script loop until a
    > certain log entry or file is present, then continue.
    >
    > Marco
    >
    I'm using PSH V1.

    A script loop was an option I did consider, but I didn't think it would work
    for only 2 Radio Buttons. The situation with the Radio Buttons is to
    determine which .reg file the installation should merge. If one is selected,
    it merge's the relevant .reg file, and if the other one is selected, it
    merges the other .reg file instead. Does that make any sense?

      My System SpecsSystem Spec

  8. #8


    Marco Shaw [MVP] Guest

    Re: Using Radio Buttons within Powershell


    > # create button
    > $button = New-Object Windows.Forms.Button
    > $button.add_click({onPress})
    > $button.text = "OK"
    > $button.height = 20
    > $button.width = 50
    > $button.top = 60
    > $button.left = 100
    > $form.controls.add($button)
    Comment out:
    $button.add_click({onPress})

    > # create event handler for button
    > $event = {
    > $form.Close()
    > }
    Change to this:
    # create event handler for button
    $event = {
    if($radiobutton.checked){write-host "button pressed"}
    if($radiobutton1.checked){write-host "button1 pressed"}
    $form.Close()
    }

    I'm just echoing out whether a button is pressed or not, put your own
    code in there...

    Marco

      My System SpecsSystem Spec

  9. #9


    Stuart.B Guest

    Re: Using Radio Buttons within Powershell



    "Marco Shaw [MVP]" wrote:

    >

    > > # create button
    > > $button = New-Object Windows.Forms.Button
    > > $button.add_click({onPress})
    > > $button.text = "OK"
    > > $button.height = 20
    > > $button.width = 50
    > > $button.top = 60
    > > $button.left = 100
    > > $form.controls.add($button)
    >
    > Comment out:
    > $button.add_click({onPress})
    >

    > > # create event handler for button
    > > $event = {
    > > $form.Close()
    > > }
    >
    > Change to this:
    > # create event handler for button
    > $event = {
    > if($radiobutton.checked){write-host "button pressed"}
    > if($radiobutton1.checked){write-host "button1 pressed"}
    > $form.Close()
    > }
    >
    > I'm just echoing out whether a button is pressed or not, put your own
    > code in there...
    >
    > Marco
    >
    Many Thanks for the suggestion Marco. I just have one last question, what
    command would I use to link each button to a particular .reg file. The code
    that I have done so far, brings up the .msi file, but once completed brings
    up the Window Form with the Radio buttons, and both .reg files one for each
    radio button at the same time. I've tried many ways to get it to work, but
    still no joy.

      My System SpecsSystem Spec

  10. #10


    Marco Shaw [MVP] Guest

    Re: Using Radio Buttons within Powershell

    >> if($radiobutton.checked){write-host "button pressed"}

    >> if($radiobutton1.checked){write-host "button1 pressed"}

    > Many Thanks for the suggestion Marco. I just have one last question, what
    > command would I use to link each button to a particular .reg file. The code
    > that I have done so far, brings up the .msi file, but once completed brings
    > up the Window Form with the Radio buttons, and both .reg files one for each
    > radio button at the same time. I've tried many ways to get it to work, but
    > still no joy.
    I'm not following... Is the .reg file that you're trying to assign to
    each radio button dynamic?

    If it is static, I would have thought you could have just put your
    command in the scriptblock above:

    if($radiobutton.checked){do_my_reg_stuff_here}
    ....

    Marco

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
Using Radio Buttons within Powershell

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I get the radio going? reece86 Media Center 0 07 Oct 2009
Web Radio erkole Media Center 1 04 Jun 2009
Grouping radio buttons w/o group box Israel .NET General 1 14 May 2009
Radio buttons do not save state after post back Goldenrate .NET General 1 06 Dec 2008
How to create a dialog box with radio buttons coolfiona VB Script 1 21 May 2008