Closing a Windows Application with LabVIEW

Updated Jan 5, 2018

Reported In

Software

  • LabVIEW Full

Operating System

  • Windows

Issue Details

I would like to close a Windows application using LabVIEW.  How can I accomplish this?

Solution

To close an application under Windows based systems, you need to use Win32 API. Win32 API allows you to use Windows Messages to control other applications. In this case, you have to use Win32 API to find the window of your application and send a message like WM_QUIT or WM_CLOSE to the application you want to close. 

To do that you need to use a Call Library Function Node VI twice with the DLL user32.dll .
Follow these steps :
  1. Place two Call Library Function Node VIs on the block diagram and select the DLL user32.dll which is found under C:\Windows\System32.
     
  2. Select the function FindWindowA in the first Call Library Function Node and put  these three parameters (the return type is 32-bits integer): 
    • hWnd (32-bits integer)
    • lpszClassName (32-bits integer)
    • lpszWindowName (pointer to a string)
       
  3. Select the function SendMessageAin the second Call Library Function Node and put these four parameters (the return type is 32-bits integer too) : 
    • hWnd (32-bits integer)
    • uMsg (32-bits integer )
    • wParam (32-bits integer )
    • lParam (32-bits integer )
       
  4. Now you just have to wire a 0 constant to the lpszClassName, and the name of the application you want to close to lpszWindowName of the FindWindow function.

  • Wire the return type of the FindWindow function to the hWnd input of the SendMessage function and wire a value of 16 in decimal or 10 in hexadecimal to the uMsg parameters and a zero constant to the last two parameters wParam and lParam

  • To use the code, type the name of the application you want to close into the Window Namecontrol. For example, to close LabVIEW, type "LabVIEW".

 

WAS THIS ARTICLE HELPFUL?

Not Helpful