Preventing Windows computers from sleeping or hibernating progamatically

製品と環境

このセクションは、サンプルの作成に使用された製品およびOSを反映します。

以下に示された製品を含め、NIのソフトウェアをダウンロードするには、ni.com/downloadsをご覧ください。

    ソフトウェア

  • LabVIEW

コードとドキュメント

添付

すべてをダウンロード

 

Overview
This project will prevent the system from sleeping when run. 


Description
There are plenty of ways of preventing a PC from sleeping or hibernating. The problem with most of them is that they require your user to remember to turn them on when running LabVIEW. If you just set the PC to never sleep then it will never go to sleep but what you really want is for it only to stay awake when collecting data with your LabVIEW program. Or you could run a third-party program like Caffiene to prevent the PC from sleeping, but this has the same problem.

Windows has an elegant way to deal with this, they are called Power Availability Requests. have you noticed that your PC never goes to sleep when watching a video? These are Power Availability Requests in action. You can make you LabVIEW program behave the same way. 
Requirements

  • LabVIEW 2012 (or compatible)
  • Windows 7 or above


Steps to Implement or Execute Code

  1. Unzip “Power Request Master 2012 NIVerified.zip”
  2. Open “Power Request 2012 NIVerified.lvproj”
  3. Run " Demo.vi"

 

Additional Information or References
VI Block Diagram

 1.png

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

 

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub

NIコミュニティのサンプルコード交換のサンプルコードは、MIT Licenseによりライセンス供与されています。

コメント
RobertoBozzolo
Proven Zealot
Proven Zealot

Thank you for this example! Informations you reported on MSDN were very helpful as I'm very often facing the problem of systems not properly confguired for unattended, long-lasting tests.

I managed to develop a similar example for LabWindows/CVI: you can find it here.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Ben_Manthey
Member
Member

Thanks, glad I could help.

—Ben

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub

drjdpowell
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast

Very useful.   But I suggest you make your cleanup functions, "Power Clear Request" and "Clear Handle", operate even if there is an error input, following the usual LabVIEW error-handling convention.

Ben_Manthey
Member
Member

drjdpowell,

I've updated the Git repository per your suggestion.Thanks!

 

—Ben

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub

Porter
Member
Member

Thanks for sharing this.

 

Have you tested it on Windows 10?

 

I'm assuming that the Git repository is this one: https://github.com/benmanthey/Power-Requests

Ben_Manthey
Member
Member

Porter, 

     You're welcome,

     Yes to both your questions.

     It works fine on Win 10 and that is my Git repository.

—Ben

 

—Ben
Prevent your computer from sleeping programmatically!
Use Power Requests
Download from GitHub