I have a form that is compiled into an .EXE. It displays a message saying your system will reboot in 5 min, please close your apps. I've run this on a few different machines and on 2 of them after the reboot this compiled .exe was STILL showing as a Process in TaskMan and the machine kept rebooting ever 5 min. Why? what in this code would cause that behavior?
# This will create a countdown timer on the form
$FormEvent_Load={
$labelTime.Text = "{0:D2}" -f $TotalTime
}
# Set countdown to 3 minutes or 180 seconds
$TotalTime = 300
$script:StartTime = (Get-Date).AddSeconds($TotalTime)
$timerUpdate.Start()
$timerUpdate_Tick={
#Use Get-Date for Time Accuracy
[TimeSpan]$span = $script:StartTime - (Get-Date)
#Update the display
$formRebootSystem.Text = $labelTime.Text = "{0:N0}" -f $span.TotalSeconds
if($span.TotalSeconds -le 0)
{
# Once 300 seconds have gone by reboot the system
Restart-Computer localhost -Force
}
}
$labelTime_Click={
#TODO: Place custom script here
}
$FormEvent_Load={
#TODO: Place custom script here
}
$labelSecondsRemainingUnti_Click={
#TODO: Place custom script here
}
Windows 10 remembers an loads processes that were running when the system shut down. They are reloaded when th system restarts. Place the timer.Start command outside of an event will likely cause this behavior.
Placing the timer.start() call in the "Shown" event of the form may prevent this.