Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Get process id from process name

 Keywords:  

Question:

I want to kill an Process from Task Manager automatic. Without using the askitemlist. How do I get a specific process name, and process id from the tListProc using ItemLocate and ItemExtract.

Answer:

The format of the process list, requires you search the list using strIndexNC instead of using the ItemExtract and ItemLocate functions....

Here is a UDF that should help...


#DefineFunction GetProcessID_UDF(proclist, procname)
	ptr=StrIndexNC(proclist,procname,0,@fwdscan)
	if ptr==0
	    Message(procname,"Not found")
	    exit
	endif
	
	ptr=StrIndex(proclist,"|",ptr,@fwdscan)
	ptr2=StrIndex(proclist,@tab,ptr,@fwdscan)
	pid=Strsub(proclist,ptr+1,ptr2-ptr-1)+0
	Return pid
#EndFunction
Addextender("wproc34i.dll")

Processlist=tListProc()
processname="notepad"
procid = GetProcessID_UDF(processlist, processname)
Message(processname,procid)

Article ID:   W15077