Is it possible to autoclose a form which uses $objform.showdialog() ? I am not able to do so. I am trying to Auto close a window once the timer is empty and execute an installation…
here is my code… Is there anyway i can autoclose the below once the timer becomes ‘0’. Below is the script…
i tried
$okbutton.add_click($okbutton.click)
$okbutton.click{$objform.close()}
but didn’t work
$HorizontalRsltn = (Get-WmiObject -Class win32_videocontroller).currenthorizontalResolution
$VerticalRsltn = (Get-WmiObject -Class win32_videocontroller).currentverticalResolution
$Formlocwidth = $HorizontalRsltn * 0.60
$Formlocheight = $VerticalRsltn * 0.65
$formwidth = $HorizontalRsltn * 0.40
$formheight = $VerticalRsltn * 0.30
$Okbtnwidth = $formwidth * 0.35
$Okbtnheight = $formheight * 0.65
$labelendwidth = $formwidth *0.98
$labelendheight = $formheight
[void][System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
[void][System.Reflection.Assembly]::LoadWithPartialName(“system.windows.forms”)
$objform = New-Object System.Windows.Forms.Form
$objform.Text = “Team Notification”
$objform.Size = New-Object System.Drawing.size($formwidth,$formheight)
$objform.StartPosition = “Manual”
$objform.Location = New-Object System.Drawing.size($Formlocwidth,$Formlocheight)
$objform.BackColor = “#0065BD”
$objform.ForeColor = “white”
$objfont = New-Object System.Drawing.Font(“Times New Roman”,12,[System.Drawing.FontStyle]::Italic)
$objform.font = $objFont
$objform.KeyPreview = $true
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size($Okbtnwidth ,$Okbtnheight)
#$OKButton.Size = New-Object System.Drawing.Size(100,30)
$OKButton.text = “OK”
$OKButton.add_click({$objform.close()})
$objform.Controls.Add($OKButton)
$objl = New-Object System.Windows.Forms.Label
$objl.Location = New-Object System.Drawing.Size(2,2)
$objl.size = New-Object System.Drawing.Size($labelendwidth,$labelendheight)
$objl.text = “A critical update for MS Office is scheduled to be installed in another 1 hour.If the installation can begin now, please Save and Close all office related application And Click ‘OK’. Else office applications will get closed automatically and installation will Proceed $text”
$objform.Controls.add($objl)
$objform.TopMost = $True
$objform.add_shown({$objform.Activate()})
$x = 21
[powershell]$command = [powershell]::Create().AddScript({
param
(
[System.Windows.Forms.Label]$label,
$x
)
While($x -gt 0){
$min = int
$text = “A critical update for MS Office is scheduled to be installed in another 30 Minutes .If the installation can begin now, please Save and Close all office related application And Click ‘OK’. Else office applications will get closed automatically and installation will Proceed`n” + " " +$min + " Minutes " + ($x %60) + “seconds left”
$label.BeginInvoke([system.action[string]]{
param($text)
$label.Text = $text}, $text)
start-sleep -Seconds 1
$x–
}
})
$command.AddParameters(@($objl, $x)) | out-null
$command.BeginInvoke() | Out-Null
$objform.showdialog()
start-sleep 2