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.


Process ID

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

tOpenProc Error 220 When Trying toTerminate a Process


I keep recieving tOpenProc error '202: Could not open process. Access denied.' when trying to terminate java.exe.

Here is my code:


Locator = ObjectOpen("WbemScripting.SWbemLocator")
Service = Locator.ConnectServer("","root/cimv2","","")
Security = Service.Security_
Security.ImpersonationLevel = 3
colAdapters = Service.ExecQuery("Select ProcessID from Win32_Process Where Caption = 'java.exe'")
hEnum = ObjectCollectionOpen(colAdapters)
While 1
 Obj = ObjectCollectionNext(hEnum)
 If Obj == 0 then Break
 ProcID = Obj.ProcessID
hProcess=tOpenProc(ProcID,3);!!!!! 202 Error Occurs Here
result = tKillProc(hProcess)

I am logged in as the local administrator, running Windows XP. I am able to terminate the process using TaskManager and IntControl 56.

What could be the problem?

Note: WinClose does not work on java.exe


First: This IntControl 56 and and tKillProc let you terminate an application abruptly. Normally, you should use WinClose to close an application gracefully, but sometimes that may not be possible. Using IntControl 56 or tKillProc is a drastic, last-resort method of terminating an app. Note: You will not receive any warning from the operating system before the application is closed, even if it contains unsaved work. Also, this function may leave the system in an unstable state. Use this function carefully.

This problem may have be resolved in version 10013 of the Process extender. It seems as though, on NT, the calling process must be given seDebugName privilege in order to open a process with the PROCESS_TERMINATE access flag (3). The tOpenProc function didn't handle this until now.

Starting in version 10013 of the Process extender:

Rev 10013  Dec 12, 2003
    Modified tOpenProc to set the SE_DEBUG_NAME privilege when using PROCESS_TERMINATE(3) on NT platforms.
Reference: MicroSoft KB Article 131065

Alternatively you can use WinItemProcId and IntControl 56 to close a process based on the Process id.

; Using WinItemProcId and IntControl 56
list=Askitemlist("Choose Java.exe from the list",idlist,@TAB,@SORTED,@SINGLE)
; parse off process ID and Name
;Get a list of window ids associates with that process id
winids = WinItemProcId(procid, 15, 0)
;Loop thru all windows and terminate them
For xx = 1 to ItemCount(winids,@tab)
  if WinExist(id) then IntControl(56,id,0,@TRUE,0)

Article ID:   W15865
File Created: 2017:07:28:12:58:39
Last Updated: 2013:04:01:08:13:56