Process.Kill:How to kill an attached debugger?

M

Manfred Braun

Hi All,

I am writing a tool, which should monitor some exe-processes, which are not
very solid. Th main function is to re-start them, if they hung, but this is
complicated. I can detect things like no longer generating IO or such
properties and I use WMI to do that. I am also looking for attached
subprocesses, which are one of the system debuggers.

I wrote a test-program, which creates a divide by zero error after some
seconds. I can detect - with the help of wmi - that my watched process get's
a subprocess attached, which is, for example, "vs7jit.exe" and I know the
handle.

Then I do:

Process p = Process.GetProcessById(pid/handle);
p.Kill();

I can verify by logging and with the help of "TLIST.EXE" [from the resource
kit], that I got the right PID and that "Kill()" works, but not as expected:
After Kill(), the debugger is not removed [the GUI stays visible] and is
appearing with another PID as a subprocess of "svchost.exe". Also using
"p.CloseMainWindow()" is not usable, because it returns false [the docs
explain one of the reasons, which fit in my case:The process has "a modal
dialog is being shown"].

How can I kill the debugger, so that my program dies [this is handled and
the process can be restarted]. Configuring the system to never display a
debugger is not an option for other reasons. The
Management.Win32_Process.Terminate method could be another option, so I post
this to the WMI group also. My proggi is written in C#.

And help would be great!!!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 
S

Scott McNairy \(MVP\)

Consider using the AppActivate method (non-WMI) combined with SendKeys to
issue the Quit command on the debugger window - it will take the attached
process down with it.

Dim l_wsh, l_bLnAppRunning, l_StrAppTitle, l_intTimeout
const c_intTimeout = 240000 ' time this script out in 4 minutes
const c_intSleeptime = 200 ' sleep for 1/4th second at a time

Set l_wsh = CreateObject("Wscript.Shell")
l_bLnAppRunning = false

l_intTimeout = 0

l_StrAppTitle = "Your Debugger Window Title"

' do this until the app activates successfully or timeout
Do While l_bLnAppRunning = False

' try to activate the application with specified title
l_bLnAppRunning = l_wsh.AppActivate(l_StrApptitle)

' closes the application
If l_bLnAppRunning Then
' send an ALT and F4 key stroke - your key stroke may vary...
l_wsh.SendKeys "%{F4}"
End If

' sleep
WScript.Sleep c_intSleeptime

' prevents a hang
if l_intTimeout >= c_intTimeout then
l_bLnAppRunning = true ' just to avoid any possible hangs
exit do
else
l_intTimeout = l_intTimeout + c_intSleeptime
end if

Loop

Wscript.Quit 0

--
Scott McNairy
Microsoft MVP - Windows Server Management Infrastructure


Manfred Braun said:
Hi All,

I am writing a tool, which should monitor some exe-processes, which are
not
very solid. Th main function is to re-start them, if they hung, but this
is
complicated. I can detect things like no longer generating IO or such
properties and I use WMI to do that. I am also looking for attached
subprocesses, which are one of the system debuggers.

I wrote a test-program, which creates a divide by zero error after some
seconds. I can detect - with the help of wmi - that my watched process
get's
a subprocess attached, which is, for example, "vs7jit.exe" and I know the
handle.

Then I do:

Process p = Process.GetProcessById(pid/handle);
p.Kill();

I can verify by logging and with the help of "TLIST.EXE" [from the
resource
kit], that I got the right PID and that "Kill()" works, but not as
expected:
After Kill(), the debugger is not removed [the GUI stays visible] and is
appearing with another PID as a subprocess of "svchost.exe". Also using
"p.CloseMainWindow()" is not usable, because it returns false [the docs
explain one of the reasons, which fit in my case:The process has "a modal
dialog is being shown"].

How can I kill the debugger, so that my program dies [this is handled and
the process can be restarted]. Configuring the system to never display a
debugger is not an option for other reasons. The
Management.Win32_Process.Terminate method could be another option, so I
post
this to the WMI group also. My proggi is written in C#.

And help would be great!!!!

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:[email protected]
(Remove the anti-spam-underscore to mail me!)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top