Reboot message box prevents system from shutting down

Hello,

We are deploying software at the german branch of a large company that Dan probably knows well :wink:

Over the last year or so, we have modified the deploy-application.ps1 to our needs, as well as added some useful functions via the AppDeployToolkitExtensions.ps1.

The countdown time for a reboot is set to 8 hours (by demand), so it doesn’t interfere with the normal workday too much. The problem is, that people tend to forget about the reboot, and then try to shutdown manually, which results in the message, that powershell is preventing the system from shutting down :frowning:

We already had incident tickets because of this, how can I prevent this situation ?

Additional info: we are using SCCM for deployment, so the toolkit is runnung as local system

-Georg

This post does a good job of explaining the problem and what needs to be done to fix it:
https://social.msdn.microsoft.com/Forums/en-US/21f87287-56e3-4327-8fb7-5c94167b1653/c-respond-to-windows-shutdown?forum=winforms

I will start looking at how to get a fix implemented for the toolkit. If you figure out a solution, let me know.

I haven’t tested this, but I think this will work. If you test it and it works, report back and I will add the fix to the toolkit.

In function Show-InstallationRestartPrompt, replace line

$formRestartClosing = [Windows.Forms.FormClosingEventHandler]{ $_.Cancel = $true }

with code:

$formRestartClosing = [Windows.Forms.FormClosingEventHandler]{
    If ($_.CloseReason -eq 'WindowsShutDown') {
        $_.Cancel = $false
    }
    Else {
        $_.Cancel = $true
    }
}

Hello Muhammad,

thank you for the quick reply. I see what you are doing here, but unfortunately in my test it doesn’t work, the form does not appear in the first place, no restart prompt is shown although the logfile says it was invoked…

I will look deeper into that subject later today.

-Georg

Try this instead and see if it works:

$formRestartClosing = [Windows.Forms.FormClosingEventHandler]{
    If ($_.CloseReason -eq 'UserClosing') {
        $_.Cancel = $true
    }
}

Hello,

today I tried the first solution again (in another package), and it actually seems to work ! There’s probably another problem with my first test package, sorry for that.

I tested this successfully on a Windows 8.1 System using SCCM 2012. Maybe now someone else could verify this, please ?

  • Georg

I think the second solution is probably the better one because we only want the normal actions a user might take to close a window to not work. If someone is trying to close the windows from the Task Manager, for example, then we should probably allow that to happen.

You can see all of the close reasons here:

I have implemented the second fix I posted above into the latest 3.6.5 beta:

Also, let have further discussion for this topic on GitHub where I created an issue for it: