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

    • Apple prices for sure suck, but performance, upgradability and flexibility are subjective to the use case and machine. For example, you will not find a mini PC in the same starting price range that has the same performance as a Mac Mini, nor will it be very upgradable, if at all at that size. Many cost-effective laptops are not upgradable past the storage. Inexpensive laptops are underperforming in comparison to more expensive models that might actually cost more than a MacBook . You won’t find battery life is comparable unless you go with Snapdragon, which limits compatibility and sacrifices upgradability. AIOs suck in both spaces, so I’ll not mention them. As for flexibility, I can do more in my use cases with a Mac than I can with a Windows or Linux machine. Where Apple really screws their users over is with upgrades, especially since you have to do them during purchase. The area where Apple can’t compete at all is desktop machines (not discussing AIOs). Outside of cost, it’s all subjective and situational.
    • Not with Proton, no. macOS isn’t Linux in any way, shape, or form.
    • AIDA64 was just showing the variable speed. Open Task Manager and go on the CPU tab and see the magic of your CPU speed going up and down as the PC does things in the background. C States Auto/Disabled actually forces all cores on (disabling the ability to park unneeded 3D Cache cores when they aren't needed), but does not have any effect on the CPU speed. I think setting the Power Plan in Windows to High Performance does boost the CPU clock higher, which also results in less energy efficiency with "everything turned up to 11" all the time when it isn't even needed. Older generation CPUs did not have the variable speeds we now have in modern CPUs, they operated on a fixed clock speed.
    • one drive saved my life .ive freed up some space i now have 227gigs.
    • "What the f is that name of that program?! Good thing I can find it in the easily accessible, and alphabetized list of apps." 🙂 I don't use the Start Menu a lot, but I'd be super annoyed if there wasn't some form of an app drawer in Windows.
  • Recent Achievements

    • One Month Later
      SekTheFirst earned a badge
      One Month Later
    • First Post
      zayanhani earned a badge
      First Post
    • First Post
      HarryTaylor earned a badge
      First Post
    • One Year In
      Eternal Tech earned a badge
      One Year In
    • One Month Later
      Eternal Tech earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      655
    2. 2
      ATLien_0
      237
    3. 3
      Michael Scrip
      231
    4. 4
      Steven P.
      141
    5. 5
      +FloatingFatMan
      138
  • Tell a friend

    Love Neowin? Tell a friend!