473,657 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Console App capturing close button event

Hi,
I have a console app, i want to be able to do some clean up when the
user exits the application. So, i need to capture the red close window
button event on the "cmd.exe" window. How can i do this?

I know that i can make my app a windows app and hide the window - right
now, this is not enough of a reason to go this route. And in that case,
i would have to have the user to go to the task manager or provide
another means to shutdown the app when needed such as another utility
program or write code into the prog to check for an already running
instance and shut it down and then continue.
thanks,
BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 19 '06 #1
3 7836
Willy posted sample how to do this
http://groups.google.com/group/micro...88a7bf4cfb4832

"Meya-awe" wrote:
Hi,
I have a console app, i want to be able to do some clean up when the
user exits the application. So, i need to capture the red close window
button event on the "cmd.exe" window. How can i do this?

I know that i can make my app a windows app and hide the window - right
now, this is not enough of a reason to go this route. And in that case,
i would have to have the user to go to the task manager or provide
another means to shutdown the app when needed such as another utility
program or write code into the prog to check for an already running
instance and shut it down and then continue.
thanks,
BRAMOIN


--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Apr 19 '06 #2
I am using C#, so i don't know how to import Kernel32 into it. in any
case, when i used the other suggestion: Binding to the process, it does
not work. Here is a simplified version of my code

namespace progName
{
class progName
{
private static progName pName = null;

public delegate void OnExited(object o, System.EventArg s e);

// other variable initializations

public progName()
{ // some object initialization }

[STAThread]
static void Main(string[] args)
{
pName = new progName();

System.Diagnost ics.Process thisProc =
System.Diagnost ics.Process.Get CurrentProess() ;

thisProc.Enable RaisingEvents = true;
thisProc.Exited += new EventHandler(pN ame.OnExited);

while(pName._sh utDown == false)
{
thisProc.WaitFo rExit();
pName._shutDown = true;
}

// psuedo code ....Call other objects shutdown
}

pubic void OnExited(object o, System.EventArg s e)
{
// psuedo code ... Call other objects shutdown
}
}
}

I put a breakpoint on the first line in OnExited and it is never called
when i close the window.

BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 19 '06 #3
Correction: Binding to the process worked and the
System.Diagnost ics.Process method did not work. Also, this binding to
the process method that i have mentioned is in the link suggested by
Willy: news:5A******** *************** ***********@mic rosoft.com...

BRAMOIN

*** Sent via Developersdex http://www.developersdex.com ***
Apr 22 '06 #4

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

Similar topics

5
1629
by: ashutosh.bhardwaj1980 | last post by:
Hi, I amdeveloping a web site in ASP and it is a secure site. I would like someone to help me on this: -->i dont want 2 users to accesss my site with the same username parallely. --> Also how can I capture window.close event in my application and then call a asp script in that function.
2
1710
by: orekin | last post by:
Hi The application I am working on has a starting screen with some configuration choices and the following: - OK button - QUIT button - x button in the Control/System menu box (top right corner) The user may quit the application by pressing 'QUIT' or x, or the user may continue with the application by pressing 'OK'. In both cases,
10
6007
by: Andrew | last post by:
Hi, I have a messagebox that pops up due to an event. I did it in javascript. ie. alert("Time's up. Assessment Ended"); I want to capture the OK and Cancel events of this alert messagebox. My code is in C#/ASP.NET. TIA. Andrew.
12
3738
by: Jarod_24 | last post by:
I got a project called "Forms" that hold some forms and stuff in my solution. A argument at startup defines wether to use a From or Console. My plan was to create a myConsole class that would also allow my application to display a Console, but i don't seem to be allowed to do this. I don't see any References that i need to add, so how do i do this.
10
8479
by: shiry | last post by:
Hi, I need to do some important cleanup before my console application exists. I used the console ctrl event. This is working well and it fires for all cases, including the CTRL_CLOSE_EVENT (if I close the application from the X botton). But on the contrary to what the MSDN indicates (ms-help://MS.VSCC.2003/MS.MSDNQTR.2003OCT.1033/dllproc/base/handlerroutine.htm), ending my process from the task manager did not fire the CTRL_CLOSE_EVENT....
3
2030
by: Sujoan | last post by:
Hi, What is WMI? Is it possible to use WMI event to capture a Toolbar button click(using RSOP_IEToolbarButton object) from a DLL(A Browser Helper Object in my project)?If so,please provide me some help on this issue.. or pls help me out if any other alternative exists in capturing a button click event from a BHO in IE.. Thanks and Regards, Sujoan.
4
1586
by: miha.vitorovic | last post by:
Hi all. I know this is more of a DOM question, but here it goes: Browser == Firefox suppose I have two frames. One has many links and is opening pages in the other one. I would like to check if the page is finished loading. This is the example of the "links" frame. ----
2
3050
by: =?Utf-8?B?TmVldGE=?= | last post by:
Hi, I creating a console application. In that I want to catch the cancel event of the console application .Please guide me in this.I figured out that I will have to attach event to the console.How can I do that? Please help ! Thanks,
2
3576
by: Nageshwarrao | last post by:
Hi All, I have a window.open() popup.In which I placed an "Close" button.when I Click on that "Close" button it will pass some information to the Database and after that the window will be closed.But if we click on the windows close button the information which i want to send to the DataBase is not working properly. So if can capture that close event in that i will call me own Function. I will be vey much thankfull, if any...
0
8392
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
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
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
7320
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...
1
6163
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
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();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1944
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1604
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.