Search code examples
.netshutdown

.NET: shutdown laptop even after close of application


Update

Situation:

I'm trying to make an application that shutdown my laptop using a simple button but when I press the button the shutdown still has to work.

Question:

Is this possible to do? And how do I have to do it? Or is this an automatic process?

Code:

I think the code should look like this:

    Private sub 
        Button1_click(ByVal...)
               Shell("shutdown /s") 
    End sub

Can someone please give me feedback if I used it correct?

Thank You


Solution

  • To restart or shutdown your computer via .net you should use process.start to run your command:

    System.Diagnostics.Process.Start
    

    In this case you need to run the shutdown command for example this option will restart your computer after a 30 second delay.

    System.Diagnostics.Process.Start("ShutDown", "/r");
    

    Update to answer adicional questions:

    • If you want to change the delay you should use the parameter /t x (x in seconds), for example /t 60 would delay the shutdown in 60 seconds.
    • The computer will still shutdown after you close the application, to abort the shutdown execute the command shutdown -a in cmd

    More information about the shutdown command:

    http://www.computerhope.com/shutdown.htm