OleObject wsh
integer li_rc
wsh = CREATE OleObject
wsh.ConnectToNewObject( "MSScriptControl.ScriptControl" )
wsh.language = "vbscript"
wsh.AddCode('function terminatenotepad() ~n ' + &
'strComputer = "." ~n ' + &
'Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") ~n ' + &
'Set colItems = objWMIService.ExecQuery("Select * from Win32_Process where name = ~'notepad.exe~'") ~n ' + &
'For Each objItem in colItems ~n ' + &
' objItem.Terminate ~n ' + &
'Next ~n ' + &
'end function ~n ' )
wsh.executestatement('terminatenotepad()')
wsh.DisconnectObject()
DESTROY wsh
[local external function declaration]
// PB10
FUNCTION ulong FindWindow(ref string classname, ref string windowname) &
LIBRARY "user32.dll" &
ALIAS FOR "FindWindowA;ansi"
// or PB10 alternate declaration
// FUNCTION ulong FindWindow (ref string classname, ref string windowname) &
// LIBRARY "user32.dll" &
// ALIAS FOR "FindWindowW"
// or PB9
// FUNCTION ulong FindWindow(ref string classname, ref string windowname) &
// LIBRARY "user32.dll" &
// ALIAS FOR "FindWindowA"
[powerscript]
ulong hWnd
string ls_title
string ls_class
ls_class = "Notepad"
SetNull(ls_name)
hWnd = FindWindow(ls_class, ls_title)
IF NOT IsNull(hWnd) THEN
// WM_CLOSE = &H10 == 16
send(hwnd, 16, 0, 0)
END IF
To close an application builded with Powerbuilder, you need a class name, it's difficult because the class name is not always the same with new PB release. With PB10, it's FNWND3100 so for PB11 it maybe FNWND3110 ...
| PB9 | ls_class = "FNWND390" |
| PB10 | ls_class = "FNWND3100" |
| PB11 | ls_class = "FNWND3110" // ?? |
You may need to use the next technique if you want to close another Powerbuilder application and not close yourself at the same time !
[local external function declaration]
// PB10
FUNCTION ulong FindWindow(ref string classname, ref string windowname) LIBRARY "user32.dll" &
ALIAS FOR "FindWindowA;ansi"
// or PB10 alternate declaration
// FUNCTION ulong FindWindow (ref string classname, ref string windowname) &
// LIBRARY "user32.dll" &
// ALIAS FOR "FindWindowW"
// or PB9
// FUNCTION ulong FindWindow(ref string classname, ref string windowname) &
// LIBRARY "user32.dll" &
// ALIAS FOR "FindWindowA"
[powerscript]
ulong hWnd
string ls_title
string ls_class
ls_name = "Untitled - Notepad"
SetNull(ls_class)
hWnd = FindWindow(ls_class, ls_title)
IF NOT IsNull(hWnd) THEN
// WM_CLOSE = &H10
send(hwnd, 16, 0, 0)
END IF
[powerscript]
ulong hWnd
string ls_title
string ls_class
ls_name = "Untitled - Notepad"
ls_class= "Notepad"
hWnd = FindWindow(ls_class, ls_title)
IF NOT IsNull(hWnd) THEN
// WM_CLOSE = &H10
send(hwnd, 16, 0, 0)
END IF
Written and compiled by Réal Gagnon ©1998-2011
[ home ]