Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any Windows XP alternative to Windows Vista's shutdown process which prompts the user whether to continue or cancel shutdown in case some programs contain an unsaved data?

share|improve this question
add comment

3 Answers

up vote 9 down vote accepted
+50

You can do this with some code by handing the SystemEvents.SessionEnding event. This will show a dialog box when you try to logoff or shutdown and ask if you want to cancel the logoff or shutdown.

The code can be compiled for free with either the Visual C# 2008 Express Edition or with the windows SDK.

With the sdk, use the following command:

csc.exe   /out:StopShutdown.exe /target:winexe StopShutdown.cs

Here's the code:

using System;
using System.Windows.Forms;
using Microsoft.Win32;

namespace StopShutdown
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
           string desktopRegKey = @"HKEY_CURRENT_USER\Control Panel\Desktop";
           Registry.SetValue(desktopRegKey, "AutoEndTasks", 0);
           Registry.SetValue(desktopRegKey, "WaitToKillAppTimeout", 20000);
           Registry.SetValue(desktopRegKey, "HungAppTimeout", 20000);

            Form AppForm = new Form()
                {
                    ClientSize = new System.Drawing.Size(0, 0),
                    ControlBox = false,
                    FormBorderStyle = FormBorderStyle.None,
                    Opacity = 0,
                    ShowIcon = false,
                    ShowInTaskbar = false,
                    SizeGripStyle = SizeGripStyle.Hide,
                };

            SystemEvents.SessionEnding += (_e, e) =>
            {
                DialogResult dr = MessageBox.Show(
                                    "Cancel shutdown?"
                                    , "Shutdown",
                                    MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question,
                                    MessageBoxDefaultButton.Button1);

                e.Cancel = (dr == DialogResult.Yes);
            };


            Application.Run(AppForm);
        }

    }
}

Edit:

Downloadable source and exe.

share|improve this answer
    
would you be a nice person and upload the "StopShutdown.exe" somewhere or email it to me? (I would understand if you said no) –  Lawand Aug 22 '09 at 20:55
2  
    
Good work, you got really close: I left an unsaved file open then I invoked shutdown from start menu, next a prompt asked me if I want to cancel shutdown but when I waited for a couple of seconds, Windows terminated your program and carried out the shutdown process... –  Lawand Aug 23 '09 at 0:25
    
Yes, if you want XP to wait longer, you'll need to modify the registry values mentioned in another post. I'll update the code... –  Scott Weinstein Aug 23 '09 at 2:24
    
Actually I want XP to halt the shutdown process permanently (like Vista does). Anyway your answer is the closest so far... –  Lawand Aug 27 '09 at 11:59
add comment

If you're willing to do a little registry editing... Start -> Run -> regedit

HKEY_CURRENT_USER\Control Panel\Desktop

Make sure AutoEndTasks is 0, and set WaitToKillAppTimeout to 20000 (the default value of 2 seconds). You can set the value higher if you wish. There's also HungAppTimeout (the defalt is 5000), but that applies more for applications which are not responding.

share|improve this answer
    
This gives more time for apps to be closed properly, but it doesn't permanently stop the shutdown process... –  Lawand Aug 19 '09 at 18:04
add comment

Whenever I do a shutdown on XP, if a program is a busy, it gives me a progress bar and an option to 'End Now' or 'Cancel'.

Clicking 'Cancel' stops the shutdown process. However, whatever it has already shutdown doesn't come back up.

But it does give me time to save what I was working on before re-attempting the shutdown.

share|improve this answer
    
But if a program is responding (not busy) it will be forced to close even if it contained unsaved data –  Lawand Aug 23 '09 at 22:18
    
that's not what you asked - if it's not responding, it doesn't matter if you're trying to shutdown or not, you'll lose unsaved data –  warren Aug 24 '09 at 0:03
    
Sorry, I shouldn't have said "busy programs", I meant programs that contain an unsaved data and that are not busy... –  Lawand Aug 24 '09 at 10:38
1  
oh, then my answer still stands - at least on plain-vanilla installs of XP: any time I've done a shutdown but had, for example, an unsaved doc in Word, I had the opportunity to cancel the shutdown, save my doc(s), and then restart the shutdown process –  warren Aug 24 '09 at 10:58
    
Couple of days ago I installed XP SP3 and now the system does what you say, whereas with SP2 it didn't... –  Lawand Sep 22 '09 at 13:18
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.