JohnLM 14 Posted December 31, 2023 specs: Win7 and Win10 In all my casual searches, I've never seen any kind of request for this. I have an app that writes the date/time down. Now, I would like to utilize it every time Windows startup or shutdown, but also when I put Windows in sleep mode and wake up from sleep, and also for Windows logon/logoff mode. I will mostly be using it during Windows sleep modes, but I need it for shutdown as well. Where do I put my app to make this happen? Share this post Link to post
Brian Evans 105 Posted December 31, 2023 (edited) Unclear what you are asking. You can't do anything "during" sleep modes as the system is asleep. If you just want dates and times for those events read the Windows Event Log where the Kernel-Power source logs events for all of those. Edited December 31, 2023 by Brian Evans Share this post Link to post
FPiette 383 Posted January 1 13 hours ago, JohnLM said: every time Windows startup or shutdown, but also when I put Windows in sleep mode and wake up from sleep, and also for Windows logon/logoff mode. Maybe you should write a program to filter Windows event log files which contains all the events you mentioned. Or maybe there is something you don't tell us... Share this post Link to post
DelphiUdIT 176 Posted January 1 (edited) You can put your program in AUTOSTART folder, and every time the program start filter the Windows events log (like others told). Sometimes (for example every day changes) filter again it. Take care that if you want to start the program for every accounts you should write some records in the Windows registry. Alternatives is that you capture the message events (like QueryEndSession and similar) to capture in realtime whats happens You must take care of user multisessions and also terminal server (or RDS). Bye Edited January 1 by DelphiUdIT Share this post Link to post
dummzeuch 1505 Posted January 1 Putting your program into the autostart folder will ensure that it is started when windows starts (or actually, when the user logs on). You can then let it run with an invisible window and handle messages that announce the other events: WM_ENDSESSION WM_POWERBROADCAST 1 Share this post Link to post
Remy Lebeau 1394 Posted January 1 (edited) On 12/31/2023 at 11:52 AM, JohnLM said: I have an app that writes the date/time down. Now, I would like to utilize it every time Windows startup or shutdown, but also when I put Windows in sleep mode and wake up from sleep, and also for Windows logon/logoff mode. Where do I put my app to make this happen? There is nowhere you can "put the app" that will make the OS run your app during sleeps/wakeups. Your app needs to already be running in order to catch those events in real-time in your app's code. As for Startup specifically, you could use the "Startup" group in the Start Menu, or the "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" key in the Registry, to run your app during startup/logon. There are also startup/shutdown and logon/logoff policy scripts that you can edit to run your app: Working with startup, shutdown, logon, and logoff scripts using the Local Group Policy Editor Edited January 1 by Remy Lebeau Share this post Link to post
JohnLM 14 Posted January 1 (edited) Remy, unfortunately, Windows 7 Home Premium does not come with any group policy editors, so that is out of the question. The gpedit.msc app does not exist on this laptop. Edited January 1 by JohnLM Share this post Link to post
Uwe Raabe 2057 Posted January 1 1 hour ago, Remy Lebeau said: There is nowhere you can "put the app" that will make the OS run your app during sleeps/wakeups. You could execute the app with a Windows Task Scheduler event triggered by the different conditions. The tricky part is to find the appropriate event ids, where The Kernel-Power Event Provider can be helpful. It also is possible that the app doesn't get the time to execute its task before the system goes to sleep and finishes it after waking up. Share this post Link to post
A.M. Hoornweg 144 Posted January 4 I would personally write such a program as a service application and let it monitor messages like WM_POWERBROADCAST to log the events. This way you can be sure that the application is always running and will capture the events when they happen. 1 Share this post Link to post
Lars Fosdal 1792 Posted January 4 I was also thinking about a service, but it might be more trouble (rights wise) to get one installed than a simple standalone app. On 1/2/2024 at 12:03 AM, Uwe Raabe said: app doesn't get the time to execute its task before the system goes to sleep Isn't there messages to respond to that can prevent/postpone the sleep? Share this post Link to post
Uwe Raabe 2057 Posted January 4 3 minutes ago, Lars Fosdal said: Isn't there messages to respond to that can prevent/postpone the sleep? AFAIK, that is only sent to applications already running. I have not tested, but when the scheduler executes the task the sleep probably cannot be avoided anymore. It should be doable to check this, but I refused to invest that time. Share this post Link to post
Lars Fosdal 1792 Posted January 4 Another thought - would it not be just as convenient to search the Windows Eventlog for the various events for start/logon/logoff/sleep/reboot/shutdown? Share this post Link to post