I'm just about at the end of my wits with this one, so i figured i'd give the rest of the world a crack at it. So we have this web app at work that we launch via a PS script. The purpose of the script is to display a form for the user to select at what resolution they want the app displayed, then launch the app in that resolution.
Now the app was written in PS version 1. It runs fine in version 2. But for the life of me i cannot get it to run properly in version 3. It runs fine if i through in a -version 2 switch, but my supervisor is insisting that i modify the script and get it to run natively in version 3.
I have narrowed it down to the portion of the code where a button press value is passed to a variable. Depending which button is pressed (2 options), a function then either launches the app or launches a password reset app. But when either button is clicked nothing happens. I've managed to determined that the variable is not receiving a value when either button is clicked.
Here is the fucntion that generates the form with the buttons:
clear $PBISReg = Get-ItemProperty -Path hkcu:\Software\PBIS $sizes = "Small (94dpi)", "Medium (121dpi)", "Medium + (150dpi)", "Large (160dpi)" $global:size1 = $winusername = $env:username #Generated Form Function
function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.10.0 # Generated On: 3/26/2012 10:32 AM # Generated By: ######################################################################## #region Import the Assemblies [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null #endregion #region Generated Form Objects $form1 = New-Object System.Windows.Forms.Form $label2 = New-Object System.Windows.Forms.Label $launch = New-Object System.Windows.Forms.Button $launch2 = New-Object System.Windows.Forms.Button $size = New-Object System.Windows.Forms.ComboBox $label4 = New-Object System.Windows.Forms.Label $database = New-Object System.Windows.Forms.TextBox $label3 = New-Object System.Windows.Forms.Label $username = New-Object System.Windows.Forms.TextBox $label1 = New-Object System.Windows.Forms.Label $timer1 = New-Object System.Windows.Forms.Timer $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $launch_OnClick= { #TODO: Place custom script here } $handler_label1_Click= { #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 $System_Drawing_Size = New-Object System.Drawing.Size #$System_Drawing_Size.Height = 316 $System_Drawing_Size.Height = 400 $System_Drawing_Size.Width = 442 $form1.ClientSize = $System_Drawing_Size $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $form1.Name = "form1" $form1.StartPosition = "CenterScreen" $Form1.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Hide $form1.Text = "Parole Board Information System (PBIS)" $form1.KeyPreview = $True $form1.Add_KeyDown({if ($_.KeyCode -eq "Enter") { ="launch";$Form1.Close()}}) $form1.Add_KeyDown({if ($_.KeyCode -eq "Escape") {$form1.Close()}}) $label2.DataBindings.DefaultDataSourceUpdateMode = 0 $label2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 13 $label2.Location = $System_Drawing_Point $label2.Name = "label2" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 50 $System_Drawing_Size.Width = 407 $label2.Size = $System_Drawing_Size $label2.TabIndex = 9 $label2.Text = "NJ State Parole Board`nParole Board Information System (PBIS)" $label2.TextAlign = 32 $form1.Controls.Add($label2) $launch.DataBindings.DefaultDataSourceUpdateMode = 0 $launch.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 150 $System_Drawing_Point.Y = 250 $launch.Location = $System_Drawing_Point $launch.Name = "launch" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 50 $System_Drawing_Size.Width = 150 $launch.Size = $System_Drawing_Size $launch.TabIndex = 8 $launch.Text = "Launch" $launch.UseVisualStyleBackColor = $True $launch.add_Click({$launchbutton="launch";$Form1.Close()}) $form1.Controls.Add($launch) $launch2.DataBindings.DefaultDataSourceUpdateMode = 0 $launch2.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 75 $System_Drawing_Point.Y = 325 $launch2.Location = $System_Drawing_Point $launch2.Name = "launch2" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 50 $System_Drawing_Size.Width = 300 $launch2.Size = $System_Drawing_Size $launch2.TabIndex = 8 $launch2.Text = "Password Reset" $launch2.UseVisualStyleBackColor = $True $launch2.add_Click({$launchbutton="launch2";$Form1.Close()}) $form1.Controls.Add($launch2) #ToolTip for launch2 button: $ToolTip = New-Object System.Windows.Forms.ToolTip $ToolTip.BackColor = [System.Drawing.Color]::LightGoldenrodYellow $ToolTip.IsBalloon = $true $ToolTip.InitialDelay = 500 $ToolTip.ReshowDelay = 500 $ToolTip.SetToolTip($launch2, "If you've forgotten your PBIS/COIN password, or just need a new one, click here") $size.DataBindings.DefaultDataSourceUpdateMode = 0 $size.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",14,0,3,1) $size.FormattingEnabled = $True $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 120 $System_Drawing_Point.Y = 180 $size.Location = $System_Drawing_Point $size.Name = "size" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 33 $System_Drawing_Size.Width = 300 $size.Size = $System_Drawing_Size $size.TabIndex = 1 foreach ($item in $displaysizes) { $size.items.add($item) } $size.text = $displaysizes -like "*Default*" $form1.Controls.Add($size) $label4.DataBindings.DefaultDataSourceUpdateMode = 0 $label4.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 180 $label4.Location = $System_Drawing_Point $label4.Name = "label4" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 100 $label4.Size = $System_Drawing_Size $label4.TabIndex = 6 $label4.Text = "Size:" $form1.Controls.Add($label4) $database.DataBindings.DefaultDataSourceUpdateMode = 0 $database.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 120 $System_Drawing_Point.Y = 80 $database.Location = $System_Drawing_Point $database.Name = "database" $database.ReadOnly = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 33 $System_Drawing_Size.Width = 300 $database.Size = $System_Drawing_Size $database.TabIndex = 5 $database.text = "Prod" $form1.Controls.Add($database) $label3.DataBindings.DefaultDataSourceUpdateMode = 0 $label3.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 80 $label3.Location = $System_Drawing_Point $label3.Name = "label3" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 23 $System_Drawing_Size.Width = 112 $label3.Size = $System_Drawing_Size $label3.TabIndex = 4 $label3.Text = "Server:" $form1.Controls.Add($label3) $username.DataBindings.DefaultDataSourceUpdateMode = 0 $username.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 120 $System_Drawing_Point.Y = 130 $username.Location = $System_Drawing_Point $username.Name = "username" $username.ReadOnly = $True $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 30 $System_Drawing_Size.Width = 300 $username.Size = $System_Drawing_Size $username.TabIndex = 1 $username.text = $winusername $form1.Controls.Add($username) $label1.DataBindings.DefaultDataSourceUpdateMode = 0 $label1.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",15,0,3,1) $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 10 $System_Drawing_Point.Y = 130 $label1.Location = $System_Drawing_Point $label1.Name = "label1" $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Height = 30 $System_Drawing_Size.Width = 113 $label1.Size = $System_Drawing_Size $label1.TabIndex = 0 $label1.Text = "Login:" $label1.add_Click($handler_label1_Click) $timer1.Interval = 20000 $timer1.add_tick({$launchbutton="launch";$Form1.Close()}) $timer1.Start() $form1.Controls.Add($label1) #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 $global:size1 = $size.text return $launchbutton } #End Function
And here is the function to which the $launchbutton value is returned:
function launchform { $button = GenerateForm $DPI = sizetodpi if ($button -eq "launch") { write-host "Launch pressed" if (Test-Path hkcu:\Software\PBIS) { } else { MD hkcu:\Software\PBIS } Set-ItemProperty -Path hkcu:\Software\PBIS -Name Override -Value 1 -type dword Set-ItemProperty -Path hkcu:\Software\PBIS -Name DPI -Value $global:size1 -type string $IE=new-object -com internetexplorer.application $IE.navigate2("http://xxxxxxxxxxx") $IE.Addressbar = 0 $IE.ToolBar = 0 $IE.StatusBar = 0 $IE.visible=$true } if ($button -eq "launch2") { write-host "password reset" if (Test-Path hkcu:\Software\PBIS) { } else { MD hkcu:\Software\PBIS } Set-ItemProperty -Path hkcu:\Software\PBIS -Name Override -Value 1 -type dword Set-ItemProperty -Path hkcu:\Software\PBIS -Name DPI -Value $global:size1 -type string $IE=new-object -com internetexplorer.application $IE.navigate2("http://xxxxxxxxxxxxx") $IE.Addressbar = 0 $IE.ToolBar = 0 $IE.StatusBar = 0 $IE.visible=$true } }
I cannot for the life of me figure out why this isnt working natively in version 3. The syntax looks alright to me, and i havent found any reason why this syntax would suddenly not work in version 3. Any help or nudge in the right direction would be greatly appreciated....