473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Process.Kill:How to kill an attached debugger?

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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)
Nov 17 '05 #1
1 3126
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" <aa@bb.cc> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
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:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Matthew Wieder | last post by:
What permissions must a user have to be able to succesffuly execute a Process.Kill? I can run it with Admin privleges but not with regular user priveleges - I get an "Access is Denied." The...
0
by: marccruz | last post by:
Given an instance of System.Diagnostics.Process, how can I get the parent process o Given an instance of System.Diagnostics.Process, how can I get the child processes For example, I start a...
4
by: Peter Steele | last post by:
I want to trap any attempts to kill my C# application and so that I can execute shutdown code and let the app die gracefully. How can this be done?
7
by: yaron | last post by:
Hi, I am looking for doing this : void OnKillProcess() { do Cleanup; } i don't want to use ~MyClass() (or Finalize), because i wan't that
0
by: Darren Mart via DotNetMonster.com | last post by:
The question: are any user groups besides Administrators permitted to kill processes? Need more info? Happy to oblige: - I'm writing a business object that will run as a service under a...
2
by: Guy_B | last post by:
Hi I am using the filesystem watcher to pick up files as they are dropped into a folder - the files are output file from another system and I have no control over that. When 'watcher raises the...
0
by: Tom Plunket | last post by:
Google indicates that wx.Process.Kill hadn't been implemented some time ago in wxPython for Win32. Is that still the case? It's kind of a drag since several sources (including wxPython wiki)...
0
by: KUTTAN | last post by:
How can i determine whether a file is being used by a any process ? senario I am creating some pdf files on a server and mails it to some people as attachment. After it i have done the coding...
0
by: News.Individual.NET | last post by:
Hi everyone, It is easy enough to get all sort of info on a running process but is it possible - as it is with WMI - to get the whole command line, that is the executable and whatever file it...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.