| Author |
Topic  |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 14 2005 : 3:16:22 PM
|
Hi Guys,
Once again I have a tough nut to crack here.
My Application (which sits all day in the Systray as cute little icon sitting next to the clock) has to do some tasks when the User wants to shutdown/logoff/reboot Windows. Namely, this is some file copying, maybe start a backup or whatever.
In order to achieve this, I catch WM_QUERYENDSESSION. But, Windows isn't patient enough for my application! Windows keeps on shutting down after a few seconds, way too early for me...
Okay, so I thought I just have to return 0 in WM_QUERYENDSESSION, check what the user wanted (logoff/shutdown/reboot) and manually shutdown Windows (ExitWindowsEx) once I finished my tasks.
So far so good, as long as the user logs off or shuts down.
But what if he chose "Reboot"? According to MSDN, it is not possible to determine if the user Shuts down or Reboots Windows while in WM_QUERYENDSESSION...
Do you have any idea? |
 |
|
|
feline
Moderator
    
United Kingdom
12803 Posts |
Posted - Jan 16 2005 : 5:10:45 PM
|
if anyone is going to run this program on winXP what about hibernating the machine? i know that in theory the machine should come back ok from this, but not all programs survive hibernation *sigh*
could you run this process every hour or even half hour? i am thinking of doing so in an incremental manor, so there is only a tiny amount of work to do when you catch the WM_QUERYENDSESSION message. the smaller you have to do, the better the odds you can do it in the time available. |
zen is the art of being at one with the two'ness |
 |
|
|
kevinsikes
Tomato Guru
    
USA
269 Posts |
Posted - Jan 21 2005 : 1:29:20 PM
|
| You can read the DWORD value from "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shutdown Settings" to determine what the user last selected from the Shut Down dialog. Click here to see the Microsoft technical document listing the possible values of this key. |
Kevin Sikes Whole Tomato Software |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 21 2005 : 2:29:11 PM
|
Wow Kevin, thanks!
I also got some news...
I dug into the "gpedit.msc" stuff recently, and found out that the "Shutdown-Scripts" are located in the registry!
HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\System\Scripts\Logoff\0\0 (for the current User) HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\State\Machine\Scripts\Shutdown\0\0 (for the whole Computer)
So far I have positive results (at least under XP, not tested 2000 yet), my Application is called up on LogOff. Had to implement Commandline-recognition, but that was a minor problem. But I'll also try your suggestion, that really is some valuable (yet unknown to many) information! Thanks!
/Edit: I have just searched this registry-key on my XP Setting, but didn't find it! However, i do find it on my vmWare Windows 2000! So it seems this information is not valid in Windows XP?
|
 |
Edited by - WannabeeDeveloper on Jan 21 2005 2:49:25 PM |
 |
|
|
jpizzi
Tomato Guru
    
USA
642 Posts |
Posted - Jan 22 2005 : 7:26:44 PM
|
| My XP box (Professional with SP-2) has the key, although without the final "s". |
Joe Pizzi |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 23 2005 : 05:21:51 AM
|
Windows XP Professional, Service Pack 2, no "Shutdown Setting(s)" here under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\...
Strange... Here's a screenshot of RegEdit showing the Key:
 |
 |
Edited by - WannabeeDeveloper on Jan 23 2005 05:27:31 AM |
 |
|
|
jpizzi
Tomato Guru
    
USA
642 Posts |
Posted - Jan 23 2005 : 3:37:56 PM
|
Well, it is there on mine. I don't remember adding it manually (although it is possible).
It is a DWORD. Mine currently has a value of 0x00000002. I think that corresponds to shutdown (as opposed to reboot, etc.). Perhaps you could add it and see if it serves the purpose? Often with Windows, registry settings are used if present, a default is used if not present.?.? |
Joe Pizzi |
 |
|
|
Old as dirt
Tomato Guru
    
USA
244 Posts |
Posted - Jan 24 2005 : 3:17:14 PM
|
I'm running XP and the registry key is there on my machine and set to 4 I guess because the last time I shut down I wanted to restart. You could do a shutdown/restart and see if that adds the key to your registry. Ken |
Ken |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 24 2005 : 3:42:21 PM
|
No, it doesn't (as I shutdown/restart my machine quite often).
One question: I am using the new "XP-Styles". Are you also? Or are you using "plain old vanilla Windows2000 look-alike" Style? |
 |
 |
|
|
Old as dirt
Tomato Guru
    
USA
244 Posts |
Posted - Jan 24 2005 : 4:28:28 PM
|
| I'm using XP styles except I force a Ctrl/Alt/Del to log on and I have a password (keeps grandchildren from scrambling my desktop - and worse). |
Ken |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 25 2005 : 02:10:52 AM
|
Ah, that may be it. I'm using XP styles and I'm logged on automagically at each Boot... I believe I do not have this Registry-entry because when using styles, you don't have a Combobox with possible selections, and the system does not have to care what action was chosen last time... this setting only makes sense when there is a combobox at the logoff screen, right?
|
 |
 |
|
|
Old as dirt
Tomato Guru
    
USA
244 Posts |
Posted - Jan 25 2005 : 09:37:41 AM
|
| Yes, it would make sense that if there is no choice at logoff, there is no choice to save. |
Ken |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 25 2005 : 11:37:24 AM
|
Oh, there still is a choice, but the "state of the last choice" is uninteresting in XP...
See:
 |
 |
 |
|
|
Old as dirt
Tomato Guru
    
USA
244 Posts |
Posted - Jan 25 2005 : 11:32:44 PM
|
How did you do that. I was going to take a screen shot of my logoff dialog but alt/Print Screen apparantly doesn't put anything in the clipboard. Anyway it says who is logged on, when they logged on and has Windows Security in the title bar with six buttons - lock computer, logoff, shutdown, change password, task manager and cancel. |
Ken |
 |
|
|
WannabeeDeveloper
Tomato Guru
    
Germany
775 Posts |
Posted - Jan 26 2005 : 04:58:20 AM
|
I'm using Hypersnap-DX for Screen-Capturing...
Well, what you see there is my default LogOff-Screen (what I get when I click on Start -> Shutdown). No "Windows Security" in the Titlebar... just that small window with the background slowly fading to grey. |
 |
 |
|
| |
Topic  |
|