Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
- [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
- if($PSVersionTable.PSVersion.Major -ge 3)
- {
- $scope = 2
- }
- else
- {
- $scope = 1
- }
- function Get-GUI()
- {
- $returnValue = $null
- $Timeleft = New-TimeSpan -Seconds 300
- $ONESEC = New-TimeSpan -Seconds 1
- $objForm = New-Object -TypeName System.Windows.Forms.Form
- $objForm.Text = "Shutdown"
- $objForm.Size = New-Object System.Drawing.Size(300,200)
- $objForm.StartPosition = "CenterScreen"
- $objForm.ShowInTaskbar = $false
- $objForm.ShowIcon = $false
- $objForm.FormBorderStyle = "FixedDialog"
- $objForm.MaximizeBox = $false
- $objForm.MinimizeBox = $false
- $objForm.KeyPreview = $true
- $objForm.Add_KeyDown({if($_.KeyCode -eq "Enter"){Invoke-Command -ScriptBlock {Set-Variable -Name returnValue -Value $objTextBox.Text -Scope $scope; $objTimer.Stop(); $objForm.Close()}}})
- $objForm.Add_KeyDown({if($_.KeyCode -eq "Escape"){Invoke-Command -ScriptBlock {Set-Variable -Name returnValue -Value "Wait" -Scope $scope; $objTimer.Stop(); $objForm.Close()}}})
- $OKbutton = New-Object System.Windows.Forms.Button
- $OKbutton.Location = New-Object System.Drawing.Size(125,120)
- $OKbutton.Size = New-Object System.Drawing.Size(75,23)
- $OKbutton.Text = "Restart"
- $OKbutton.Add_Click({Invoke-Command -ScriptBlock {Set-Variable -Name returnValue -Value "Restart" -Scope $scope; $objTimer.Stop(); $objForm.Close()}})
- $objForm.Controls.Add($OKbutton)
- $Cancelbutton = New-Object System.Windows.Forms.Button
- $Cancelbutton.Location = New-Object System.Drawing.Size(200,120)
- $Cancelbutton.Size = New-Object System.Drawing.Size(75,23)
- $Cancelbutton.Text = "Wait"
- $Cancelbutton.Add_Click({Invoke-Command -ScriptBlock {Set-Variable -Name returnValue -Value "Wait" -Scope $scope; $objTimer.Stop(); $objForm.Close()}})
- $objForm.Controls.Add($Cancelbutton)
- $objLabel = New-Object System.Windows.Forms.Label
- $objLabel.Location = New-Object System.Drawing.Size(10,20)
- $objLabel.Size = New-Object System.Drawing.Size(280,40)
- $objLabel.Text = "Your computer will Restart in $($Timeleft.Minutes):$($Timeleft.Seconds) minutes.`nClick Restart to restart now.`nClick Wait to postpone for 15 minutes."
- $objForm.Controls.Add($objLabel)
- <#$objTextBox = New-Object System.Windows.Forms.TextBox
- $objTextBox.Size = New-Object System.Drawing.Size(100, 20)
- $objTextBox.Location = New-Object System.Drawing.Size(10, 120)
- $objTextBox.TextAlign = "Center"
- $objTextBox.ReadOnly = $true
- $objTextBox.Text = [string]$Timeleft.Minutes + ":" + $Timeleft.Seconds
- $objForm.Controls.Add($objTextBox)#>
- $objTimer = New-Object System.Windows.Forms.Timer
- $objTimer.Interval = 1000
- function Do-Tick()
- {
- $Timeleft = $Timeleft - $ONESEC
- $objLabel.Text = "Your computer will Restart in $($Timeleft.Minutes):$($Timeleft.Seconds) minutes.`nClick Restart to restart now.`nClick Wait to postpone for 15 minutes."
- If($Timeleft.TotalSeconds -lt 1)
- {
- Set-Variable -Name returnValue -Value "Restart" -Scope $scope
- $objForm.Close()
- }
- }
- $objTimer.Add_Tick({Do-Tick})
- $objTimer.Start()
- $objForm.TopMost = $true
- $objForm.Add_Shown($objForm.Activate())
- [Void]$objForm.ShowDialog()
- return $returnValue
- }
- Get-GUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement