Posts: 44
Threads: 12
Joined: Apr 2006
Hi
I need to know how to destroy an application. clo+ does not seem to work for me. I need a command that works like the windows task manager where you can destroy frozen programs
thanks, nate
Posts: 12,140
Threads: 142
Joined: Dec 2002
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)
Posts: 129
Threads: 38
Joined: May 2006
This function is giving me an unknown identifier. I am using version 2.1.6. My other computer is on 2.1.4 but I have not tried it there. Is this only available on 2.1.8?
Posts: 44
Threads: 12
Joined: Apr 2006
pid=GetProcessId(_s)
this line of code, seventh line from buttom, the getprocessId is not in blue when I copy and paste it into my version of qm... why is that..
Posts: 129
Threads: 38
Joined: May 2006
Same here. That is the line that gave the error.
Posts: 12,140
Threads: 142
Joined: Dec 2002
Yes, it is only available in QM 2.1.8. You can create function GetProcessId and paste this code:
;/
function# $exename
int pid fl hs k; str s se(exename); lpstr ss
if(se.endi(".exe")) fl|1
hs=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS 0); if(hs==-1) ret
PROCESSENTRY32 pe.dwSize=sizeof(PROCESSENTRY32)
k=Process32First(hs &pe)
rep
,if(!k) break
,ss=&pe.szExeFile
,s.getfilename(ss fl)
,if(s~se) pid=pe.th32ProcessID; break
,k=Process32Next(hs &pe)
,
CloseHandle(hs)
ret pid
Delete both these functions when you'll upgrade to 2.1.8 or later.
This is not tested on 2.1.6. May give more unknown identifier errors.
Posts: 129
Threads: 38
Joined: May 2006
Yes, I just tried it on 2.1.6 and got "CreateToolhelp32Snapshot" error in GetProcessId.
Posts: 1,769
Threads: 410
Joined: Feb 2003
It is only available in QM 2.1.8 so you'll have to update.
Posts: 12,140
Threads: 142
Joined: Dec 2002
In Qm 2.1.6, these functions etc should be declared somewhere. Find(toolbar -> Find) them, copy and paste in the next line after function# $exename.
Posts: 129
Threads: 38
Joined: May 2006
:oops: I just lost you there lmao!
Anyhow, I found this on previous post and modified it. Won't this work?
int process_handle
process_handle=("notepad.exe")
..
clo "notepad"
TerminateProcess process_handle 1
CloseHandle process_handle
To use TerminateProcess, must be the execution file?
or how about this one. also found this on previous post:
run "notepad.exe"
60
clo "Notepad"
ShutDownProcess win("- Notepad")
Posts: 44
Threads: 12
Joined: Apr 2006
im trying to get the first code to work but now im getting a bad agument error on this line
case else end ES_BADARG
Posts: 129
Threads: 38
Joined: May 2006
Wouldn't it be better if there was a separate function to check if the application is actually frozen before you try to shut it down? I am not sure if this is even possible but Guru Gintaras here have been a very good magician :lol:
Posts: 12,140
Threads: 142
Joined: Dec 2002
Quote:check if the application is actually frozen before you try to shut it down
Search forum for IsHungAppWindow.
Quote:case else end ES_BADARG
Delete this line.
Posts: 44
Threads: 12
Joined: Apr 2006
not what im looking for. I just want a very simple function that will destroy the application just like "windows task manager"...... If its frozen or not.. clo or clo+ will not close it if its frozen so that wont work..' sorry, I just cant get the ones working that you posted..Is there something simpler?
thanks, nate
Posts: 44
Threads: 12
Joined: Apr 2006
sorry guys still cant make it work.. I take notpad as an example. you know when you close notepad and this child window pops up asking if you want to save your work.
I need a function that will destroy the program if the child window pops up or not. So no matter what It should destroy the program or teminate the whole proccess
thanks for your help anyone.
Posts: 12,140
Threads: 142
Joined: Dec 2002
ShutDownProcess win("" "Notepad")
|