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

    • And of course that battery is the thing I'll need to replace sooner or later. It's starting to act a little flaky in its charge meter and that glue is just annoying to deal with. No need for it to be glued in place.
    • I'll say you are 50% correct. On the content side, yes, YouTube's content is basically free. Some might point out that they share ad revenue with creators, but I'll side with you saying that doesn't count. If the ad isn't viewed, the creator gets nothing from YouTube, so viewing the content is net-zero for everyone, not net-negative. The other half of the equation is the platform costs. Both YouTube and Netflix have a cost to provide their service. Netflix bakes the cost into their plans, which can be plainly seen by the different resolutions offered at different tiers, which is a pure platform cost. As you pointed out, YouTube doesn't pay licensing fees, so their entire cost structure is the platform. Using that platform without watching the ads (or paying for premium) is not net-zero like above, in this case it is net-negative. You consumed resources on YouTube systems that YouTube very clearly is not offering for free, they expect compensation in the form of viewing ads or paying for premium. TLDR, the company offering the service sets the price, either in currency or ad viewing. As the consumer, you can choose to make that agreement or not. Consuming the service without paying the price is not being offered.
    • Exactly that, in my case it doesn't work at all!
    • Last chance to download The Cybersecurity Control Playbook (worth $100) for free by Steven Parker Claim your complimentary eBook worth $100 for free, before the offer ends on June 4. Implement effective cybersecurity measures for all organizations Cybersecurity is one of the central concerns of our digital age. In an increasingly connected world, protecting sensitive data, maintaining system integrity, and ensuring privacy have never been more important. The Cybersecurity Control Playbook offers a step-by-step guide for implementing cybersecurity controls that will protect businesses and prepare them to compete in an overwhelmingly networked landscape. With balanced coverage of both foundational and advanced topics, and concrete examples throughout, this is a must-own resource for professionals looking to keep their businesses safe and secure. Readers will also find: Clear, jargon-free language that makes it accessible to a wide range of readers An introduction to developing, deploying, monitoring, testing, and retiring controls and control frameworks across large, medium, and small enterprises A system for identifying, prioritizing, and managing cyber risks based on the MITRE ATT&CK framework, with additional coverage of other key cybersecurity frameworks The Cybersecurity Control Playbook is ideal for cybersecurity practitioners, IT professionals, and security managers who are responsible for implementing and managing cybersecurity strategies in their organizations. How to get it Please ensure you read the terms and conditions to claim this offer. Complete and verifiable information is required in order to receive this free offer. If you have previously made use of these free offers, you will not need to re-register. While supplies last! Download The Cybersecurity Control Playbook (worth $100) for free Offered by Wiley, view other free resources The below offers are also available for free in exchange for your (work) email: The Cybersecurity Control Playbook ($100 Value) FREE – Expires today 6/4 The Embedded Linux Security Handbook ($31.99 Value) FREE – Expires today 6/4 Teach Yourself VISUALLY Microsoft 365, 2nd Edition ($20 Value) FREE – Expires 6/4 Winxvideo AI V3.0 Lifetime License for PC ($69.95 Valued) FREE – Expires 6/8 Aiarty Image Enhancer for PC/Mac ($85 Value) FREE – Expires 6/8 Solutions Architect's Handbook, Third Edition ($42.99 Value) FREE – Expires 6/10 AI and Innovation ($21 Value) FREE – Expires 6/11 Macxvideo AI ($39.95 Value) Free for a Limited Time – Expires 6/22 The Ultimate Linux Newbie Guide – Featured Free content Python Notes for Professionals – Featured Free content Learn Linux in 5 Days – Featured Free content Quick Reference Guide for Cybersecurity – Featured Free content We post these because we earn commission on each lead so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. Other ways to support Neowin The above deal not doing it for you, but still want to help? Check out the links below. Check out our partner software in the Neowin Store Buy a T-shirt at Neowin's Threadsquad Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: An account at Neowin Deals is required to participate in any deals powered by our affiliate, StackCommerce. For a full description of StackCommerce's privacy guidelines, go here. Neowin benefits from shared revenue of each sale made through the branded deals site.
    • I use Firefox for all the reasons already mentioned above and I also use Edge mainly because I like the snappiness of it. It does seem snappier then Firefox to me. I figure I might as well have 1 of each type browser engine. I probably won't use Edge as much once they follow in Googles footsteps of killing my ad blocker. I play around with several other browsers usually when I see an updated story on them here just to see if they can persuade me to stick with them, but they usually don't. Have never figured out what it is about Google Chrome that makes others like it so much? Heck, it isn't even smart enough to give you an option to alphabetize your bookmarks!
  • Recent Achievements

    • Week One Done
      mywakehealth earned a badge
      Week One Done
    • Dedicated
      jbatch earned a badge
      Dedicated
    • Week One Done
      Leonard grant earned a badge
      Week One Done
    • One Month Later
      portacnb1 earned a badge
      One Month Later
    • Week One Done
      portacnb1 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      295
    2. 2
      snowy owl
      162
    3. 3
      +FloatingFatMan
      156
    4. 4
      ATLien_0
      143
    5. 5
      Xenon
      125
  • Tell a friend

    Love Neowin? Tell a friend!