-1

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

DonDjango
  • 84
  • 1
  • 9

2 Answers2

3

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

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Kauê Gimenes
  • 1,278
  • 1
  • 13
  • 30
  • Is it possible to delay the shutdown more than 30 seconds? – DonDjango Jun 12 '13 at 17:01
  • Yes use the /t parameter. for example /t 60 for 60 seconds. – Kauê Gimenes Jun 12 '13 at 17:08
  • Yes I see, and I should always express it in seconds? So if I use /t 120 it will be delayed 2 minutes? And what about closing? If I close the form/application does the shutdown aborts or is it still counting down? – DonDjango Jun 12 '13 at 17:17
  • Just updated my answer to address your new questions, yes /t 120 will delay the shutdown in 2 minutes. And the shudown will still counting down, you need to execute a command to abort (explained in my answer) – Kauê Gimenes Jun 12 '13 at 17:19
  • Oh ok! Thank you :) That was what I need! If I could vote I would vote, but I can't, I'm sorry. But still Thank You! – DonDjango Jun 12 '13 at 17:29
0

You could just create a windows shortcut that executes:

shutdown -s -t 0

Or if you want to do this from C# (for example), have your C# program execute this:

Process.Start("shutdown","-s -t 0");
John Sibly
  • 22,782
  • 7
  • 63
  • 80