05-26-2006, 07:21 PM
Function ShutdownProcess2:
;/
function VARIANT'hwndOrExename [flags] ;;flags: 1 process id
;Terminates a process (running program).
;Preferred method to close program is clo or clo+, but if does not work (eg when hung), use this function.
;This function may leave invalid tab in taskbar.
;hwndOrExename - program name (without exe), or handle of some window that belongs to the process, or process id (then use flag 1).
;EXAMPLES
;ShutDownProcess2("NOTEPAD")
;ShutDownProcess2(win("" "Notepad"))
def PROCESS_TERMINATE 0x0001
int ph pid ghost
sel hwndOrExename.vt
,case VT_I4
,pid=hwndOrExename.lVal
,if(flags&1=0)
,,if(!pid) ret
,,if(wintest(pid "" "Ghost" "explorer")) end "It is a ghost window that belongs to EXPLORER process. To find correct window, use class name."
,,GetWindowThreadProcessId(pid &pid)
,case VT_BSTR
,_s=hwndOrExename
,pid=GetProcessId(_s)
,case else end ES_BADARG
if(!pid) ret
ph=OpenProcess(PROCESS_TERMINATE 0 pid)
if ph
,TerminateProcess(ph 0)
,CloseHandle(ph)