Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to cancel System from Shutdown using C#.net

How to cancel System from Shutdown using C#.net

Scheduled Pinned Locked Moved C#
csharptutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    K V Sekhar
    wrote on last edited by
    #1

    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.

    V M S 3 Replies Last reply
    0
    • K K V Sekhar

      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.

      V Offline
      V Offline
      Vimalsoft Pty Ltd
      wrote on last edited by
      #2

      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

      K 1 Reply Last reply
      0
      • K K V Sekhar

        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.

        M Offline
        M Offline
        Matjaz xyz
        wrote on last edited by
        #3

        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!

        1 Reply Last reply
        0
        • K K V Sekhar

          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.

          S Offline
          S Offline
          sph3rex
          wrote on last edited by
          #4

          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.

          M 1 Reply Last reply
          0
          • S sph3rex

            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.

            M Offline
            M Offline
            Matjaz xyz
            wrote on last edited by
            #5

            Exactly. For more information on the shutdown function, you can go Start/Run and open "cmd" and then type "shutdown /?".

            Força Barça!

            1 Reply Last reply
            0
            • V Vimalsoft Pty Ltd

              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

              K Offline
              K Offline
              K V Sekhar
              wrote on last edited by
              #6

              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!"); } }

              D 1 Reply Last reply
              0
              • K K V Sekhar

                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!"); } }

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups