![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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) $script G.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 Specs![]() |
| | #2 (permalink) |
| | Re: Using Radio Buttons within Powershell Stuart.B wrote: Quote: > 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. wait for them to complete. I've not tried your WinForms code yet... Marco |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Using Radio Buttons within Powershell Quote: > #show Form > $form.Add_Shown({ > $script:dt = (&$scriptBlock | out-dataTable) > $script G.DataSource = $DT.psObject.baseobject> $Rows.Text="[Rows:$($script:dt.rows.count)]" > $dg.AutoResizeColumns() > $form.Activate() > }) > > $form.showdialog() > } Marco |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Using Radio Buttons within Powershell "Marco Shaw [MVP]" wrote: Quote: > Quote: > > #show Form > > $form.Add_Shown({ > > $script:dt = (&$scriptBlock | out-dataTable) > > $script G.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 > 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) $script G.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 Specs![]() |
| | #5 (permalink) |
| | 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: Quote: > Stuart.B wrote: Quote: > > 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 Specs![]() |
| | #6 (permalink) |
| | Re: Using Radio Buttons within Powershell Quote: > 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??? 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 Specs![]() |
| | #7 (permalink) |
| | Re: Using Radio Buttons within Powershell "Marco Shaw [MVP]" wrote: Quote: > Quote: > > 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 > 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 Specs![]() |
| | #8 (permalink) |
| | Re: Using Radio Buttons within Powershell Quote: > # 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) $button.add_click({onPress}) Quote: > # create event handler for button > $event = { > $form.Close() > } # 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 Specs![]() |
| | #9 (permalink) |
| | Re: Using Radio Buttons within Powershell "Marco Shaw [MVP]" wrote: Quote: > Quote: > > # 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}) > Quote: > > # 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 > 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 Specs![]() |
| | #10 (permalink) |
| | Re: Using Radio Buttons within Powershell >> if($radiobutton.checked){write-host "button pressed"} Quote: Quote: >> if($radiobutton1.checked){write-host "button1 pressed"} Quote: > 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. 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 Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Web Radio | Media Center | |||
| Grouping radio buttons w/o group box | .NET General | |||
| Radio buttons do not save state after post back | .NET General | |||
| How to create a dialog box with radio buttons | VB Script | |||
| radio in wmp 11 | Vista General | |||