#Generated Form Function function GenerateForm { ######################################################################## # Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.3.0 # Generated On: 8/31/2009 8:25 AM # Generated By: Jeffery Hicks ######################################################################## #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 $statusBar1 = New-Object System.Windows.Forms.StatusBar $rtbResults = New-Object System.Windows.Forms.RichTextBox $btnGo = New-Object System.Windows.Forms.Button $txtComputername = New-Object System.Windows.Forms.TextBox $label1 = New-Object System.Windows.Forms.Label $btnQuit = New-Object System.Windows.Forms.Button $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState #endregion Generated Form Objects #---------------------------------------------- #Generated Event Script Blocks #---------------------------------------------- #Provide Custom Code for events specified in PrimalForms. $GetBootTime= { $errorActionPreference="SilentlyContinue" $rtbResults.Clear() $computername=$txtComputername.Text $statusBar1.text="Connecting to {0}" -f $computername.toUpper() $form1.Refresh() $os=Get-WmiObject win32_operatingsystem -computername $computername -ea SilentlyContinue if ($os.lastbootuptime) { $line1="Last boot: {0}" -f $os.ConvertToDateTime($os.lastbootuptime) $line2=$rtbResults.text="Uptime : {0}" -f ((get-date) - $os.ConvertToDateTime($os.lastbootuptime)).tostring() $rtbResults.Text=$line1+ "`n" + $line2 } else { $rtbResults.Text=("Failed to connect to {0}" -f $computername.toUpper()) } #clear variables Clear-Variable line1 Clear-Variable line2 Clear-Variable os $statusBar1.text="Ready" } $btnQuit_OnClick= { $form1.Close() } $OnLoadForm_StateCorrection= {#Correct the initial state of the form to prevent the .Net maximized form issue $form1.WindowState = $InitialFormWindowState } #---------------------------------------------- #region Generated Form Code $form1.Font = New-Object System.Drawing.Font("Tahoma",8.25,0,3,1) $form1.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon('c:\test\boot.ico') $form1.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,192) $form1.Text = 'Boot Time' $form1.Name = 'form1' $form1.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 221 $System_Drawing_Size.Height = 170 $form1.ClientSize = $System_Drawing_Size $form1.FormBorderStyle = 1 $form1.add_Shown($GetBootTime) $statusBar1.Name = 'statusBar1' $statusBar1.Text = 'Ready' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 221 $System_Drawing_Size.Height = 22 $statusBar1.Size = $System_Drawing_Size $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 0 $System_Drawing_Point.Y = 148 $statusBar1.Location = $System_Drawing_Point $statusBar1.DataBindings.DefaultDataSourceUpdateMode = 0 $statusBar1.TabIndex = 5 $form1.Controls.Add($statusBar1) $rtbResults.Name = 'rtbResults' $rtbResults.ReadOnly = $True $rtbResults.Text = '' $rtbResults.DataBindings.DefaultDataSourceUpdateMode = 0 $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 57 $rtbResults.Location = $System_Drawing_Point $rtbResults.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,192) $rtbResults.BorderStyle = 0 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 189 $System_Drawing_Size.Height = 43 $rtbResults.Size = $System_Drawing_Size $rtbResults.TabIndex = 4 $form1.Controls.Add($rtbResults) $btnGo.TabIndex = 3 $btnGo.BackColor = [System.Drawing.Color]::FromArgb(255,240,240,240) $btnGo.Name = 'btnGo' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnGo.Size = $System_Drawing_Size $btnGo.UseVisualStyleBackColor = $False $btnGo.Text = 'Get Time' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 117 $btnGo.Location = $System_Drawing_Point $btnGo.DataBindings.DefaultDataSourceUpdateMode = 0 $btnGo.add_Click($GetBootTime) $form1.Controls.Add($btnGo) $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 189 $System_Drawing_Size.Height = 21 $txtComputername.Size = $System_Drawing_Size $txtComputername.DataBindings.DefaultDataSourceUpdateMode = 0 $txtComputername.Text = $env:computername $txtComputername.Name = 'txtComputername' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 13 $System_Drawing_Point.Y = 30 $txtComputername.Location = $System_Drawing_Point $txtComputername.TabIndex = 2 $form1.Controls.Add($txtComputername) $label1.TabIndex = 1 $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 172 $System_Drawing_Size.Height = 23 $label1.Size = $System_Drawing_Size $label1.Text = 'Enter a computername:' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 12 $System_Drawing_Point.Y = 9 $label1.Location = $System_Drawing_Point $label1.DataBindings.DefaultDataSourceUpdateMode = 0 $label1.Name = 'label1' $form1.Controls.Add($label1) $btnQuit.TabIndex = 0 $btnQuit.BackColor = [System.Drawing.Color]::FromArgb(255,240,240,240) $btnQuit.Name = 'btnQuit' $System_Drawing_Size = New-Object System.Drawing.Size $System_Drawing_Size.Width = 75 $System_Drawing_Size.Height = 23 $btnQuit.Size = $System_Drawing_Size $btnQuit.UseVisualStyleBackColor = $False $btnQuit.Text = 'Quit' $System_Drawing_Point = New-Object System.Drawing.Point $System_Drawing_Point.X = 127 $System_Drawing_Point.Y = 117 $btnQuit.Location = $System_Drawing_Point $btnQuit.DataBindings.DefaultDataSourceUpdateMode = 0 $btnQuit.add_Click($btnQuit_OnClick) $form1.Controls.Add($btnQuit) #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