views:

44

answers:

2

I have to write a C# application that runs on WindowsME. Yes, I mean that Microsoft operating system that has been forgotten a long long time ago. My program needs no user interaction and as WindowsME doesn't support services, it will be a console application. Furthermore it will be used on more modern operating systems, where the user can choose whether to start it as console application or install it as a windows service. Now suppose the software is running on WinME and the user decides to logoff or shutdown the machine without a prior quit of my software. WinME complains about my program still running and asks if it should kill the process. Apart from the bad user experiance, this means that the application is not shut down properly.

So I look for a way to be informed if the user logs off or wants to shutdown the machine to be able to perform a proper shutdown of my software first.

+1  A: 

I think WM_ENDSESSION is supported by Windows ME so I think you should try to catch that event. That's the one sent out to all top level windows when the Windows session is ending (via logout or shutdown).

ho1
I think WM_ENDSESSION came along with win2000 (NT branch of Windows). I don't recall if it was ever in win9x.
dkackman
I'm not certain either, I found some links that seemed to indicate that someone had used it in Win98, but I didn't find anything official and it's not like I've got a Win98/WinME test system hanging around to try it out :)
ho1
+1  A: 

Have you tried handling SystemEvents.SessionEnding/SystemEvents.SessionEnded? To use this you will need to create a hidden form, I believe the MSDN example demonstrates this.

http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx

Chris Taylor