Run program before hibernation/sleep


Recommended Posts

When i press the sleep-button on my computer i want to run a program before windows goes to sleep.

How to do?

I have tried hibernate trigger (http://www.desimonesystems.com/suspendtrigger/index.php) but it only starts the program before the hibernation starts, it doesn't wait for the program to finish (they say it should but maybe it doesn't work fully in vista).

My program has to finish (takes about 5-10sec) before windows go into sleep.

I don't care how advanced the solution is, i really really need this.

Link to comment
https://www.neowin.net/forum/topic/746664-run-program-before-hibernationsleep/
Share on other sites

Would executing a batch file work? Try experimenting with the start command, specifically "start /w". The /w flag tells it to wait for the program to finish executing.

For example, this batch file (save as "dir-hibernate.bat") would display a directory & then hibernate.

@echo off

start /w cmd /c "dir /a c:\windows"

shutdown /h /f

exit

Keep in mind, if the program you're executing before hibernate hangs up or waits for you to click/enter something, it's never going to hibernate since it'll be stuck waiting..I'm guessing you've already considered that :)

  lars77 said:
Would executing a batch file work? Try experimenting with the start command, specifically "start /w". The /w flag tells it to wait for the program to finish executing.

For example, this batch file (save as "dir-hibernate.bat") would display a directory & then hibernate.

@echo off

start /w cmd /c "dir /a c:\windows"

shutdown /h /f

exit

Keep in mind, if the program you're executing before hibernate hangs up or waits for you to click/enter something, it's never going to hibernate since it'll be stuck waiting..I'm guessing you've already considered that :)

That's actually almost what i'm doing now.

In my program that requires the action before sleep i've added a hibernate button so as long as i hibernate through the program everything is fine.

But i'm looking for a solution that works no matter how you put the computer to sleep. It's pretty stupid to have a computer that can't go to sleep after being idle X minutes or by using the normal sleep-buttons :(

You could maybe try monitoring Windows' system events, pretty much all power events will get logged in the event log. In this way you can catch pretty much all types of sleep/poweroff events. But I'm not sure if you can make make standby/hibernate "wait" until your program is done doing what it's doing (maybe if you somehow cancel it & then re-submit the standby/hibernate request afterwards?). These might be helpful:

http://nico.berlee.nl/#/on-standby-close-mce

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

Just be careful about any solutions that force the user to wait for their machine to sleep, or prevent it from sleeping altogether. eg: Users hate it when their laptop doesn't go to sleep when it was supposed to :p

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They forgot this slide: "If I get a Mac I won't be able to play games, therefore I will have more time for my studies."
    • It’s not desperation, it’s marketing. Companies do that…
    • Some AMD Ryzen users can get free Windows performance boost with this simple system tweak by Sayan Sen AMD understands that there is a lot of demand for its X3D processors and for good reason too, since they offer some of the best gaming experiences. As such, the company plans to launch a new 6-core Ryzen 5 9600X3D for those who may not want to spend top dollar on a 9800X3D. What makes X3D special is the densely packed last level cache (LLC) wherein the L3 (level 3) cache is 3D die-stacked such that there is a whole lot of it that the cores can access on demand all within the smallest footprint. This is said to help with latency especially, and games happen to be quite sensitive to it since they are a mixed workload and so there is a lot of to-and-fro. However, despite that fact, users have noticed micro-stuttering and freezes on Ryzen X3D CPUs. Although there is no official fix, some of the affected users have managed to resolve the issues by tweaking a motherboard setting. The tweak is related to a setting called "GLOBAL C-STATE CONTROL" (it may be called something else by your motherboard vendor) and changing it to 'Enabled' from 'Auto' could fix stuttering and lag-related issues in games. If you are not familiar with them, Processor Power Management is done through Advanced Configuration and Power Interface (ACPI) P-states or C-states. While P-states or performance states handle CPU voltage-frequency scaling, C-states deal with CPU sleep states so that some of the CPU functions, which are not necessary at that moment, are disabled. The P-states and C-states work together to make the processor run more efficiently. It helps the OS and apps determine which cores can be parked. The Global C-state control setting helps users manage not only the DF and CPU core C-states but also the I/O C-states too. For those wondering, DF here refers to Data Fabric or AMD's high bandwidth Infinity Fabric interconnect between CPUs, GPUs, and more, on AMD systems. By default, this is set to "Auto" which also means that it is "Enabled" by default. However, in the case of X3D parts, Auto may set this setting to "Disabled" and thus manually toggling it to "Enabled" may be necessary. X3D processors, the dual CCD (core complex die) ones especially, have their V-cache on a single CCD. If the CPPC (Collaborative Processor Performance Control), which lets an OS like Windows control the "preferred core" and clock speed boost, isn't working optimally to assign the correct gaming CCD, then this fix could well work. Global C-State Auto: Global C-State Enabled: We ran a benchmark on our Ryzen 9 9950X3D to see if toggling the settings would make a difference, and well, it didn't in the case of AIDA64. However, since this is a synthetic test that measures cache and memory exclusively, we can't definitively conclude that the fix will also not make a difference in the case of games. Another remedy for stuttering is to disable the monitoring of the "Power percent" metric on MSI Afterburner if you have it on. This has been a long-known issue and in fact can help you even if you are not using an X3D CPU. Source: Reddit (link1, link2) via YouTube
    • I only have one contact on WhatsApp. And that contact has sms also. I have many more contacts that use WhatsApp also, but everyone defaults to use iMessage, SMS or RCS anyway. Not a loss for me. I'm in Norway where mostly nobody uses WhatsApp.
    • Apple is boring for a kid. Only fun is browsing websites for HTML games. A PC with steam is another story. Of course if the child plays video games all day then maybe that might not be a good idea. :-)
  • Recent Achievements

    • One Month Later
      DecaffKnight94 earned a badge
      One Month Later
    • Dedicated
      S.P earned a badge
      Dedicated
    • One Month Later
      adxnksd42031 earned a badge
      One Month Later
    • Rising Star
      aphanic went up a rank
      Rising Star
    • Contributor
      GravityDead went up a rank
      Contributor
  • Popular Contributors

    1. 1
      +primortal
      663
    2. 2
      ATLien_0
      261
    3. 3
      Michael Scrip
      234
    4. 4
      Steven P.
      157
    5. 5
      +FloatingFatMan
      151
  • Tell a friend

    Love Neowin? Tell a friend!