How to cancel System from Shutdown using C#.net
-
Hi all, I am working Windows application. I have a requirement of downloading the files from a website. When the application is runnning (downloading files), if user shutdown the the system i need to cancel that shutdown and i have to display message like "Downloading files is not completed.You want stop Downloading files, if yes Click on btn_ShutDown ,if not btn_CancelShutDown. For that i used Form1_Closing Event. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { // I dont know the actual logic, but i tried the below one. But its not working e.Cancel; // But its not working. } } Please suggest me how to cancel the Shutdowning of system. Thanks in advance.
-
Hi all, I am working Windows application. I have a requirement of downloading the files from a website. When the application is runnning (downloading files), if user shutdown the the system i need to cancel that shutdown and i have to display message like "Downloading files is not completed.You want stop Downloading files, if yes Click on btn_ShutDown ,if not btn_CancelShutDown. For that i used Form1_Closing Event. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { // I dont know the actual logic, but i tried the below one. But its not working e.Cancel; // But its not working. } } Please suggest me how to cancel the Shutdowning of system. Thanks in advance.
see this http://www.dotnetspider.com/resources/4541-Cancel-shutdown-e-computer.aspx[^] and http://www.dreamincode.net/forums/showtopic33948.htm[^] Hope its what you want, but if you googled before you post , i promised you would have found it too :)
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
Hi all, I am working Windows application. I have a requirement of downloading the files from a website. When the application is runnning (downloading files), if user shutdown the the system i need to cancel that shutdown and i have to display message like "Downloading files is not completed.You want stop Downloading files, if yes Click on btn_ShutDown ,if not btn_CancelShutDown. For that i used Form1_Closing Event. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { // I dont know the actual logic, but i tried the below one. But its not working e.Cancel; // But its not working. } } Please suggest me how to cancel the Shutdowning of system. Thanks in advance.
I dont know how to get the status of windows, if its shutting down, but u can use, i think, this code on if the user doesnt want to shutdown. add this: using System.Diagnostics; // code for canceling the shutdown Process.Start("shutdown -a"); // code for shutting down Process.Start("shutdown -s"); //The process command is just like Start/Run ;) I hope somebody helps you with "if shutting down" Regards, Matjaž
Força Barça!
-
Hi all, I am working Windows application. I have a requirement of downloading the files from a website. When the application is runnning (downloading files), if user shutdown the the system i need to cancel that shutdown and i have to display message like "Downloading files is not completed.You want stop Downloading files, if yes Click on btn_ShutDown ,if not btn_CancelShutDown. For that i used Form1_Closing Event. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { // I dont know the actual logic, but i tried the below one. But its not working e.Cancel; // But its not working. } } Please suggest me how to cancel the Shutdowning of system. Thanks in advance.
call "shutdown -a" after fetching the reason either using the System.Process namespace either using Microsoft.VisualBasic.Interaction.Shell to cancel the windows shutdown. Also if the user hits shutdown choosing to abort file download, run with one of the options specified above the following shell command: "shutdown -s" for shutdown or "shutdown -r" for restart or "shutdown -t [time_in_seconds] -[r or s] for a "timed" restart or shutdown.
Code? Yeah i love it fried together with a glass of wine.
-
call "shutdown -a" after fetching the reason either using the System.Process namespace either using Microsoft.VisualBasic.Interaction.Shell to cancel the windows shutdown. Also if the user hits shutdown choosing to abort file download, run with one of the options specified above the following shell command: "shutdown -s" for shutdown or "shutdown -r" for restart or "shutdown -t [time_in_seconds] -[r or s] for a "timed" restart or shutdown.
Code? Yeah i love it fried together with a glass of wine.
Exactly. For more information on the shutdown function, you can go Start/Run and open "cmd" and then type "shutdown /?".
Força Barça!
-
see this http://www.dotnetspider.com/resources/4541-Cancel-shutdown-e-computer.aspx[^] and http://www.dreamincode.net/forums/showtopic33948.htm[^] Hope its what you want, but if you googled before you post , i promised you would have found it too :)
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
Thanks for your replay. I already tried the logic present in the link http://www.dotnetspider.com/resources/4541-Cancel-shutdown-e-computer.aspx[^] But it's not worked. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { Microsoft.VisualBasic.Interaction.Shell("shutdown -a", AppWinStyle.MinimizedFocus, false, -1); MessageBox.Show("Shutdown process cancelled!"); } }
-
Thanks for your replay. I already tried the logic present in the link http://www.dotnetspider.com/resources/4541-Cancel-shutdown-e-computer.aspx[^] But it's not worked. private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason.Equals(CloseReason.WindowsShutDown)) { Microsoft.VisualBasic.Interaction.Shell("shutdown -a", AppWinStyle.MinimizedFocus, false, -1); MessageBox.Show("Shutdown process cancelled!"); } }
It doesnt' work because you cannot start new .EXE's while a shutdown is in progress and -a only aborts a PENDING shutdown, one which hasn't happened yet, so you're code is getting notified too late. This[^] is how you really should do it. But, you really shouldn't be doing this at all.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008