Programmatically Acquiring a Screenshot in a LabVIEW Executable

Updated Oct 21, 2020

Environment

Software

  • LabVIEW

Operating System

  • Windows

I would like to acquire a screenshot while running my LabVIEW application.  How can I do this programmatically once the application has been deployed as an executable?

To take a screenshot from an executable, utilize the Windows user32.dll to take a screenshot and access the stored image from the clipboard. This can be seem in the Programmatically Acquire Screenshot in Executable Application example. 

The structure of the example is to:
  1. Use Call Library Function Node to access user32.dll (which can be found in C:\Windows\System32\user32.dll).
  2. Call the keybd_event function which enables the simulation of a key press (seen in figure 1).
  3. Simulate the press of the Print Screen button which stores the image in the clipboard.
  4. Access image data stored to the clipboard via the use of the .NET method, Clipboard GetImage (seen in figure 2).
Note: This VI must be set to run in a single thread (run in UI thread).
 

Figure 1: Using user32.dll calls to simulate pressing the Print Screen keyboard key
 

Figure 2: Using user32.dll calls to capture the image on the clipboard and save to a file.

Additional Information

LabVIEW provides a simple invoke method, Clipboard. Get Image, which can be used to acquire an image from the Windows Clipboard. However, this invoke method is not supported in the LabVIEW Run-Time environment.