Share this page 

Terminate an another applicationTag(s): Powerscript

We post the WM_QUIT message to an application (developped with Powerbuilder or not) to close it.

In this example, if the Windows Calculator is running then it will be closed from Powerscript.

The target window handle is retrieved by looking at its title.

[local external function declaration]
FUNCTION ulong FindWindowA(ulong classname, String windowname) & 
  LIBRARY "user32.dll"
FUNCTION boolean PostMessageA&
  (ulong hwndle,UINT wmsg,ulong wParam,ulong lParam) & 
  LIBRARY "user32.dll"
CONSTANT uint WM_QUIT = 18 // hex 0x0012
ulong     lul_handle
string    ls_app

ls_app = "Calculator"
//  ls_app = "Calculatrice"  in french windows!

lul_handle = FindWindowA(0, ls_app)

IF lul_handle > 0 THEN 
   PostMessageA(lul_handle, WM_QUIT, 0, 0);
   MessageBox("Oups", ls_app + " is not running!")