Example Code

Programmatically turn off monitor with user32.dll

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example uses user32.dll to programmatically control the power state of the a computer's monitor.

 

Description

The user32.dll can be used to programmatically control the power state of the a computer's monitor. This function can be called using the Call Library Function Node to call PostMessage(). The API for the function being called can be found on MSDN: http://msdn.microsoft.com/en-us/library/ms644944. The code broadcasts a message to all windows to turn off the monitor. It will then stay off until the user provides input, such as moving the mouse. The same function can be used to then turn the monitor back on. Here is another useful page that explains how the function works. http://www.codeproject.com/KB/cs/Monitor_management_guide.aspx

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code 

  1. Verify that user32.dll is at the following location: C:\Windows\System32\user32.dll.
  2. If not, relink the the Call Library Function Node to where user32.dll is located
  3. Run the VI, and let your monitor turn off.
  4. Move your mouse or wait 10 seconds for the monitor to turn back on.
  5. The second call can be disabled so the monitor won't turn back on until user input such as moving the mouse.

 

Additional Information or References

VI Snippet

1.png

 

 

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

Danny Funk -- Senior Group Manager -- Software R&D -- NI

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.