473,785 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gracefully terminate after force quit?

Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles
Nov 17 '05 #1
7 5758
Andrew,

You can use the classes in the System.Manageme nt namespace to do this.
Basically, you would get all instances of the WMI class Win32_Process and
then attach to the event when an instance is deleted.

However, this might be pretty hefty in terms of performance. From what
I understand, it polls the process, instead of getting a notification.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Andrew S. Giles" <An**********@d iscussions.micr osoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles

Nov 17 '05 #2
Nicholas,

Thanks for the nudge int he right direction, I will look into the
System.Manageme nt namespace to see if I want to implement this.

Andrew

"Nicholas Paldino [.NET/C# MVP]" wrote:
Andrew,

You can use the classes in the System.Manageme nt namespace to do this.
Basically, you would get all instances of the WMI class Win32_Process and
then attach to the event when an instance is deleted.

However, this might be pretty hefty in terms of performance. From what
I understand, it polls the process, instead of getting a notification.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Andrew S. Giles" <An**********@d iscussions.micr osoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles


Nov 17 '05 #3

"Andrew S. Giles" <An**********@d iscussions.micr osoft.com> wrote in message
news:F1******** *************** ***********@mic rosoft.com...
Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles


There is no event to be catched when you kill a process, when Tasman "Ends a
Process", it calls Win32's TerminateProces s that does exactly that without
cooperating with the CLR's shutdown code.
Note that a process cannot prevent itself from being terminated, if this is
what you are looking for.

Willy.


Nov 17 '05 #4

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:us******** ******@TK2MSFTN GP09.phx.gbl...

"Andrew S. Giles" <An**********@d iscussions.micr osoft.com> wrote in
message news:F1******** *************** ***********@mic rosoft.com...
Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the
event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles


There is no event to be catched when you kill a process, when Tasman "Ends
a Process", it calls Win32's TerminateProces s that does exactly that
without cooperating with the CLR's shutdown code.
Note that a process cannot prevent itself from being terminated, if this
is what you are looking for.

Willy.


Haven't looked into it much, but what about system processes? How do they
keep from being shut down? This would be good to know if writing drivers
and such :)

Mythran
Nov 17 '05 #5
Mythran wrote:
Haven't looked into it much, but what about system processes? How do
they keep from being shut down? This would be good to know if
writing drivers and such :)


Techically, system process can be shut down. The reason they cannot
"normally" is because they're running in a special space that requires more
privileges to shut down which, by default and by design, task manager
doesn't have.

It is quite possible to elevate task manager with the right permissions such
that it can terminate anything.

Note that this is exceptionally dangerous because if you terminate, for
example, CSRSS.exe, the entire system blue-screens.

To see how to do this, and the full details of what I'm talking about, check
here:

http://www.microsoft.com/msj/0398/win320398.aspx

As for how to get your own processes to run in this "protected space",
really, just make it a service.

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]
Nov 17 '05 #6

"Mythran" <ki********@hot mail.comREMOVET RAIL> wrote in message
news:uZ******** ******@TK2MSFTN GP09.phx.gbl...

"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:us******** ******@TK2MSFTN GP09.phx.gbl...

"Andrew S. Giles" <An**********@d iscussions.micr osoft.com> wrote in
message news:F1******** *************** ***********@mic rosoft.com...
Hello,

I am looking for an article, or some information about how to get a C#
windows forms application to trap the "End Process" event from the Task
Manager?

Is such a thing possible, and if so, where is the information on the
event
the would be raised located in the .NET framework?

Thanks in advance for your help and information.

Andrew S. Giles


There is no event to be catched when you kill a process, when Tasman
"Ends a Process", it calls Win32's TerminateProces s that does exactly
that without cooperating with the CLR's shutdown code.
Note that a process cannot prevent itself from being terminated, if this
is what you are looking for.

Willy.


Haven't looked into it much, but what about system processes? How do they
keep from being shut down? This would be good to know if writing drivers
and such :)

Mythran


If you mean processes that run as SYSTEM, those can all except a few be
killed by administrators, those who can't are created with a Process token,
restricting access to SYSTEM only. As Administrator you can change such
token the P. Token using a Resource kit tool Pview.exe.
Drivers do not run in a process, they are hosted by the Kernel process.

Willy.



Nov 17 '05 #7

"Reginald Blue" <Re***********@ hotmail.com> wrote in message
news:d3******** **@trsvr.tr.uni sys.com...
Mythran wrote:
Haven't looked into it much, but what about system processes? How do
they keep from being shut down? This would be good to know if
writing drivers and such :)


Techically, system process can be shut down. The reason they cannot
"normally" is because they're running in a special space that requires
more
privileges to shut down which, by default and by design, task manager
doesn't have.

It is quite possible to elevate task manager with the right permissions
such
that it can terminate anything.

Note that this is exceptionally dangerous because if you terminate, for
example, CSRSS.exe, the entire system blue-screens.

To see how to do this, and the full details of what I'm talking about,
check
here:

http://www.microsoft.com/msj/0398/win320398.aspx

As for how to get your own processes to run in this "protected space",
really, just make it a service.

--
Reginald Blue
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my
telephone."
- Bjarne Stroustrup (originator of C++) [quoted at the 2003
International Conference on Intelligent User Interfaces]

Taskman runs in the context of the Interactive Logon user, if this happens
to be an administrator, you will be able to kill services unless they are
running with a restricted Process Token (mostly SYSTEM owner). In that case
the process can only be killed by SYSTEM.
Now, the question is how do I run as SYSTEM, too easy, run cmd.exe as a
service in the context of SYSTEM and bingo.
Willy.
Nov 17 '05 #8

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

Similar topics

8
5123
by: Gregor Lingl | last post by:
I'm working on a windows machine I've written a Tkinter-app (sort of game) which consists mainly of an animation which is driven by a while True: ... loop. If I close the App's window by clicking the right upper standard-X-Button, the program doesn't terminate cleanly. Instead a somewhat cryptic error message is displayed, e.g.:
4
5743
by: KB | last post by:
Hi, I want to write a Python script that controls and automates a Windows GUI computation program. My problem is that I do not know how to quit the Windows GUI program gracefully with a command (program's or Python) in Cygwin. 'kill' or CTRL-C command in Cygwin does not finish it gracefully, meaning that some outputs do not come out normally. The only thing I know is to click 'File-Exit' menu, but
4
2464
by: Lauren Quantrell | last post by:
If an Access2K ade is running, say it's named app1.ade, and I open app2.ade, I want app2.ade to determine if app1.ade is running, and if it is, I want app2.ade to close app1.ade. Is this easy? lq
1
1368
by: Claude Gagnon | last post by:
Hi, I program with Visual C++ .NET 2003. I have an application that I want to quit if a specific date is passed. (the user will not choose Quit in the menu) I want to terminate the application in the OnClose member function of my CApplicationView class. I have tried with various methods like
7
8421
by: Frank | last post by:
Hi, I have a console app that I want to stop gracefully by another program. The console app already has code to intercept control-c and logoff and so on. But how do I send a control-c to that console app from another program? The console application is started with a Process class. Thanks Frank
4
2188
by: sherifffruitfly | last post by:
Hi, I load the contents of an excel sheet into a dataset via the excel object library (couldn't get the #$%#$^ oledb/ado route to work - #^$%&^%$ connection strings... grrr.... ) Anyway, after I get the sheet's contents into my dataset, I'd love to jettison excel. Calling ExcelApp.Quit() has no effect until I exit the entire application. How can I force excelapp.quit() to take effect when the line is executed?
2
19189
by: Joannes Vermorel | last post by:
We have developed an open-source eCommerce sales forecasting add-on in PHP (see link below) that requires usually more than a few seconds to complete because the process involves some Web Services communications. http://community.lokad.com/PhpSalesForecasting.ashx Yet, in shared hosting with short PHP execution timeouts, our script may not terminate (being killed by the web server). Our concern is not the timeout in itself, it's the...
5
2751
by: cnsabar | last post by:
Hi., I want to call some function when the user force to terminate the perl program. For example., I write a program to create a file when the program starts... Also I need to delete a file when the user force to terminate the process i.e Calling some function when the user hitting Ctrl+C in perl command prompt..
3
3862
by: Gros Bedo | last post by:
Hello :-) I have a question about Python and Linux shell. I have a python program which is permanently resident in the end-user system. I'm currently producing a RPM package, and it works nicely. The problem is that when I uninstall it, my program keeps running in the background, even if the files are deleted. I know I can terminate python shell directly, but this is not a good ideabecause the end-user may be working with another important...
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10085
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.