Prevent Windows from Going to Sleep While my LabVIEW Program Runs

Updated Oct 30, 2023

Reported In


  • LabVIEW

Operating System

  • Windows

Issue Details

I have some LabVIEW code that runs for a long time. When left alone, my Windows PC goes to sleep and the code stops running, how can I stop this happening?


Listed below are 3 options to prevent your Windows PC from going to sleep while your LabVIEW program runs:

1. Change the PC Sleep Settings

The fastest and simplest way to solve this is to change the PC settings so that it never goes to sleep.

For Windows 10:

Go to Windows Settings>>System>>Power & Sleep and under Sleep, set both of the drop down boxes to Never as shown below:


For Windows 7:

Go to Control Panel»Hardware and Sound»Power Options»Edit Plan Settings and select Never under sleep.

Note: These settings may potentially be restricted under some company IT policies.

2. Use Windows Power Request Functions

A more practical way of doing this is to use Power Request Functions from the Windows API. These allow you to programmatically prevent the PC from sleeping within LabVIEW at run-time.
These can be used with the Call Library Function Node. A power request must be created with PowerCreateRequest, then set with PowerSetRequest. Once the program is finished, the handle to the request must be closed with PowerClearRequest.

This example program demonstrates how this is done, and includes a library of SubVIs that simplifies calling these functions.


3. Use a Third Party Program

There are a number of different 3rd party programs available that prevent a PC from sleeping. One of the more popular options for this is Caffeine, a program that simulates a key-press every minute to stop the PC from sleeping.
The downside to this solution is that the user must remember to run the third party program before leaving the PC running. This program is also available on MacOS on the App Store.