Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Set up the form
- #Load the required .NET libraries
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- function foobar() {
- #$a = gwmi win32_bios
- #echo $a
- $comp = '.'
- $stuff = gwmi -class "win32_localtime" -namespace "root/CIMV2" -computername $comp
- foreach ($thingie in $stuff) {
- [void]$ourlistbox.items.Add('Day' + $thingie.Day)
- }
- }
- function trollface() {
- $last = gwmi -query "select LastBootUpTime from win32_operatingsystem"
- $last.ConvertToDateTime($last.LastBootUpTime)
- [void]$objTextBox.items.Add('Bootup time:' + $last)
- }
- #Create the plain form
- $ourForm = New-Object System.Windows.Forms.Form
- $ourForm.Text = "Our Practice Powershell Application"
- $ourForm.Size = New-Object System.Drawing.Size(1024,1000)
- $ourForm.StartPosition = "CenterScreen"
- $ourForm.KeyPreview = $True
- $objLabel2 = new-object System.Windows.Forms.Label
- $objLabel2.Location = new-object System.Drawing.Size(10,10)
- $objlabel2.Size = new-object System.Drawing.Size(96,20)
- $objLabel2.Text = "Misc text."
- $ourForm.Controls.Add($objLabel2)
- #Add listbox
- $ourListbox = New-Object System.Windows.Forms.Listbox
- $ourListbox.Location = New-Object System.Drawing.Size(10,40)
- $ourListbox.Size = New-Object System.Drawing.Size(200,64)
- $ourForm.Controls.Add($ourListbox)
- #Add a command button to close form
- $closeButton = New-Object System.Windows.Forms.Button
- $closeButton.Location = New-Object System.Drawing.Size(145,150)
- $closeButton.Size = New-Object System.Drawing.Size(75,23)
- $closeButton.Text = "Close"
- $closeButton.Add_Click({$ourForm.Close()})
- $ourForm.Controls.Add($closeButton)
- #Add a command button to activate form
- $runButton = New-Object System.Windows.Forms.Button
- $runButton.Location = New-Object System.Drawing.Size(230,150)
- $runButton.Size = New-Object System.Drawing.Size(75,23)
- $runButton.Text = "Run"
- $runButton.Add_Click({foobar})
- $ourForm.Controls.Add($runButton)
- $objLabel1 = new-object System.Windows.Forms.Label
- $objLabel1.Location = new-object System.Drawing.Size(400,40)
- $objlabel1.Size = new-object System.Drawing.Size(96,20)
- $objLabel1.Text = "Last bootup time."
- $ourForm.Controls.Add($objLabel1)
- $objTextBox = new-object System.Windows.Forms.TextBox
- $objTextBox.Location = new-object System.Drawing.Size(500,40)
- $objTextBox.Size = new-object System.drawing.size (260,90)
- $ourForm.Controls.Add($objTextBox)
- #Add a command button to activate form
- $printButton = New-Object System.Windows.Forms.Button
- $printButton.Location = New-Object System.Drawing.Size(310,150)
- $printButton.Size = New-Object System.Drawing.Size(85,23)
- $printButton.Text = "Print"
- $printButton.Add_Click({trollface})
- $printButton.Add_Click({$objTextBox.Text=trollface})
- $ourForm.Controls.Add($printButton)
- #Activate the form
- $ourForm.Add_Shown({$ourForm.Activate()})
- [void] $ourForm.ShowDialog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement