How to close specific windows application when Computer is turned off or is restarted .
-
I have developed a windows application in C#.net that is running in the background like an antivirus. But the problem is whenever i try to switch off my computer or try to restart my computer, the computer doesn't turns off/restarts. And when i individually kills that windows(.exe) application listed out in Processes tab in Windows Task Manager and then tries to switch off the computer or restart it, Everything seems to be fine. How could i enhance or optimize my code so that whenever computer is turned off or is restarted, my application process should be killed automatically. Is there any class in .Net that could possibly find out , when computer is switched off or is restarted, so that i could kill down my application process at that time. Anyone who could help me out in fixing the bug. Thanks in Advance!! :^)
Aspiring Techie, Vishnu Nath
-
I have developed a windows application in C#.net that is running in the background like an antivirus. But the problem is whenever i try to switch off my computer or try to restart my computer, the computer doesn't turns off/restarts. And when i individually kills that windows(.exe) application listed out in Processes tab in Windows Task Manager and then tries to switch off the computer or restart it, Everything seems to be fine. How could i enhance or optimize my code so that whenever computer is turned off or is restarted, my application process should be killed automatically. Is there any class in .Net that could possibly find out , when computer is switched off or is restarted, so that i could kill down my application process at that time. Anyone who could help me out in fixing the bug. Thanks in Advance!! :^)
Aspiring Techie, Vishnu Nath
When Windows wants to shut down it attempts to close all running applications cooperatively and your app must have refused that close request. Have you coded a FormClosing event handler to stop the application closing? e.g.
private void Form1\_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; }
The good news is that you can fix it. Take a look at the FormClosingEventArgs.CloseReason Property and code something like this.
private void Form1\_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.WindowsShutDown) { e.Cancel = false; } else { e.Cancel = true; } }
Alan.
modified on Thursday, February 12, 2009 11:17 AM
-
When Windows wants to shut down it attempts to close all running applications cooperatively and your app must have refused that close request. Have you coded a FormClosing event handler to stop the application closing? e.g.
private void Form1\_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; }
The good news is that you can fix it. Take a look at the FormClosingEventArgs.CloseReason Property and code something like this.
private void Form1\_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.WindowsShutDown) { e.Cancel = false; } else { e.Cancel = true; } }
Alan.
modified on Thursday, February 12, 2009 11:17 AM
You are right Alan. I have coded the same way as u have mentioned, to keep my apps running in the background. Now i will change the code to your mentioned code. Thanks for the solution. Anyways is there any method where i can start my application and put the notification icon in system tray silently in the background, whenever computer is switched on or is restarted. It is similar to Gtalk or anti- virus starting their application whenever computer is turned on or is restarted. And also Alan, i want my application to behave like system process, so that no one could possibly kill that process from windows task manager processes list, except when computer is switched off. I have seen that you can cannot kill anti-virus processes from windows task manager. How do one convert their application into system processes ensuring that the application could not be killed by administrator of computer(except when comp is switched off). Looking for a solution to this Alan! :doh:
Aspiring Techie, Vishnu Nath
-
You are right Alan. I have coded the same way as u have mentioned, to keep my apps running in the background. Now i will change the code to your mentioned code. Thanks for the solution. Anyways is there any method where i can start my application and put the notification icon in system tray silently in the background, whenever computer is switched on or is restarted. It is similar to Gtalk or anti- virus starting their application whenever computer is turned on or is restarted. And also Alan, i want my application to behave like system process, so that no one could possibly kill that process from windows task manager processes list, except when computer is switched off. I have seen that you can cannot kill anti-virus processes from windows task manager. How do one convert their application into system processes ensuring that the application could not be killed by administrator of computer(except when comp is switched off). Looking for a solution to this Alan! :doh:
Aspiring Techie, Vishnu Nath
Vishnu Nath wrote:
I have seen that you can cannot kill anti-virus processes from windows task manager.
You mean that you don't know how to kill that antivirus proces - that doesn't mean that it's not possible. I'm killing the Norton-scanner prior to each build, since Visual Studio requires the resources.
Vishnu Nath wrote:
could not be killed by administrator of computer
I'd consider that a ransom-situation. The administrator owns the damn machine, and should have some control over what it does. Such programs are "malware" and Norton (or Avast, or MacAfee if they still exist) will try to remove it. There's a huge difference in limiting the enduser and in limiting the administrator. Be carefull not to mix up both user-types :-\
I are troll :)
-
Vishnu Nath wrote:
I have seen that you can cannot kill anti-virus processes from windows task manager.
You mean that you don't know how to kill that antivirus proces - that doesn't mean that it's not possible. I'm killing the Norton-scanner prior to each build, since Visual Studio requires the resources.
Vishnu Nath wrote:
could not be killed by administrator of computer
I'd consider that a ransom-situation. The administrator owns the damn machine, and should have some control over what it does. Such programs are "malware" and Norton (or Avast, or MacAfee if they still exist) will try to remove it. There's a huge difference in limiting the enduser and in limiting the administrator. Be carefull not to mix up both user-types :-\
I are troll :)
You are right. Thanks for your valuable advice and an important guidance to my project. Thanks a Lot!! :-D
Aspiring Techie, Vishnu Nath
-
I have developed a windows application in C#.net that is running in the background like an antivirus. But the problem is whenever i try to switch off my computer or try to restart my computer, the computer doesn't turns off/restarts. And when i individually kills that windows(.exe) application listed out in Processes tab in Windows Task Manager and then tries to switch off the computer or restart it, Everything seems to be fine. How could i enhance or optimize my code so that whenever computer is turned off or is restarted, my application process should be killed automatically. Is there any class in .Net that could possibly find out , when computer is switched off or is restarted, so that i could kill down my application process at that time. Anyone who could help me out in fixing the bug. Thanks in Advance!! :^)
Aspiring Techie, Vishnu Nath
-
Hi, I think here you can run a small windows service related to your application, but am not sure about it. or can try IPC concept. regards,
ashok
Alan has given out me correct solution to my problem. And now i dont face any problem in shutting down my PC after rectifying my code. ;)
Aspiring Techie, Vishnu Nath