WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Process ID

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

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")
AddExtender("wwprc44i.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)

Exit

Answer:

tCloseProc is only meant to close an open process handle, opened with tOpenProc. tKillProc is meant to terminate a process...
;Addextender("wproc34I.dll")
AddExtender("wwprc44i.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:   W14550
Filename:   tCloseProc( ) to Close a Program.txt
File Created: 2013:04:01:09:12:16
Last Updated: 2013:04:01:09:12:16