tCloseProc( ) to Close a Program
Keywords:
Question:
Currently I am trying to close a Program with WinBatch, but I am unable to get it to close with the tCloseProc( ), but I can kill it with the tKillProc( ) command.The purpose of this program is the automation of exiting and closing Outlook, when going from a offline notebook with Off-line Outlook to On-line Via a VPN which kicks off the Script to Close Outlook and restart it On-line.
Here is an example of my code:
Addextender("wproc34I.dll") id=tListProc() handle = FileOpen("c:\stuff.txt", "WRITE") FileWrite(handle, id) FileClose(handle) a= StrIndex(id, "OUTLOOK.exe", 1, @FWDSCAN) b = StrSub(id,(a+12), 3) Olookid = int(b) flag=3 handle2=tOpenProc(Olookid,flag) tKillProc(handle2) tCloseProc(handle2) ExitAnswer:
tCloseProc is only meant to close an open process handle, opened with tOpenProc. tKillProc is meant to terminate a process...Addextender("wproc34I.dll") proclist=tlistproc() ;Get pointers to proc-name and proc-id procptr=StrIndexNc(proclist,"OUTLOOK.EXE",1,@FWDSCAN) if procptr==0 then exit pipeptr=StrIndexNc(proclist,"|",procptr,@FWDSCAN) tabptr=StrIndexNc(proclist,@tab,pipeptr,@FWDSCAN) ;handle if process is at end of string if tabptr == 0 then tabptr=strlen(proclist) procname=StrSub(proclist,procptr,pipeptr-procptr) procid=StrSub(proclist,pipeptr+1,tabptr-pipeptr) if Procid!="" hProcess=tOpenProc(procid,3);PROCESS_TERMINATE if hProcess tKillProc(hProcess) tcloseproc(hProcess) Message("tKillProc","%procname% is terminated") endif else Message("tKillProc","Need a valid process id") endif
Article ID: W14550Filename: tCloseProc( ) to Close a Program.txt