Closing a Windows Application with LabVIEW

Updated Sep 9, 2026

Environment

Software

  • LabVIEW Full

Operating System

  • Windows

In this article, you will learn how to close an application in Windows systems using the Win32 API within LabVIEW. By sending Windows Messages such as WM_CLOSE, you can programmatically control and exit other running applications. This process involves using the Call Library Function Node to interface with the user32.dll.

Follow these steps :

 

 

1. Configure FindWindowA

 

  1. Place a Call Library Function Node on the block diagram and double-click it to open the configuration dialog

  2. Select the DLL:
    1. (LabVIEW 32-bit) - C:\Windows\SysWOW64\user32.dll
    2. (LabVIEW 64-bit) - C:\Windows\System32\user32.dll 

  3. Select the function FindWindowA.

  4. Select Run in UI thread and stdcall (WINAPI).
  5. Switch to the Parameters tab. Configure the parameters: 

    • lpClassName
      • Type: Numeric
      • Constant: False
      • Data Type: Signed 32-bit
      • Pass: Value
    • lpWindowName
      • Type: String
      • Constant: False
      • String format: C String Pointer
      • Minimum Size: <None>
  6. Configure the return value:

    • hWnd
      • Type: Numeric
      • Data type: Signed 32-bits integer

  7. Review your function prototype, it should look like this

    int32_t FindWindowA(int32_t lpClassName, CStr lpszWindowName);

 

 

 2. Configure SendMessageA

 

  1. Place a second Call Library Function Node. Double-click it to open the configuration dialog.

  2. Select the DLL:
    1. (LabVIEW 32-bit) - C:\Windows\SysWOW64\user32.dll
    2. (LabVIEW 64-bit) - C:\Windows\System32\user32.dll 

  3. Select the function SendMessageA.

  4. Select Run in UI thread and stdcall (WINAPI).

  5. Switch to the Parameters tab. Configure the parameters:  
    • hWnd
      • Type: Numeric
      • Constant: False
      • Data Type: Signed 32-bit
      • Pass: Value
    • Msg
      • Type: Numeric
      • Constant: False
      • Data Type: Signed 32-bit
      • Pass: Value
    • wParam
      • Type: Numeric
      • Constant: False
      • Data Type: Signed 32-bit
      • Pass: Value
    • lParam
      • Type: Numeric
      • Constant: False
      • Data Type: Signed 32-bit
      • Pass: Value
  6. Set the return type to Void 

  7. Check the function prototype. It should look like this:

    void  SendMessageA(int32_t hWnd, int32_t Msg, int32_t wParam, int32_t lParam);

 

 

3. Build the VI

 

  1. Create error in and error out controls in your front panel. Pass the error cluster through both instances of the Call Library Function Node to connect the error control to the indicator.

  2. Wire a 0 constant to the lpClassName, and the name of the application you want to close to lpWindowName of the FindWindowA function.
    1. To use the code, type the name of the application you want to close into the Window Name control. For example, to close a Microsoft PowerPoint project, enter Presentation1 - PowerPoint. Check that the name is entered exactly as it appears in the window title to ensure that the application closes correctly.

  3. Wire the return type of the FindWindowA function to the hWnd input of the SendMessageA function and wire a value of 16 (WM_CLOSE) in decimal to the Msg parameters and a zero constant to the last two parameters wParam and lParam.


Your block diagram should look like this.

 

Note: This image is a LabVIEW snippet, which includes LabVIEW 32-bit code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.