Home > C#, VB.NET > How to Shutdown, Restart, Log off your computer with VB.NET or C#

How to Shutdown, Restart, Log off your computer with VB.NET or C#

This is extremely easy using VB.NET or C# (pronounced C sharp) and the built in windows EXE file shutdown.exe. To shutdown, restart, or log off your computer is as simple as entering 1 line into your program, it just so happens that the 1 line is identical whether you’re using VB.NET or C#.

To shutdown/turn off your computer, just execute the following line of code:

1
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 0")

To restart/reboot your computer, just execute the following line of code:

1
System.Diagnostics.Process.Start("shutdown.exe", "-r -t 0")

To log off your computer, just execute the following line of code (and yes, that’s a lowercase L, not the number 1):

1
System.Diagnostics.Process.Start("shutdown.exe", "-l -t 0")

The number zero at the end of each of those examples is how long the computer should wait in seconds before shutting down/restarting/etc… In this example, I’m going to shutdown the computer in 5 minutes (5 minutes * 60 seconds = 300 seconds)

1
System.Diagnostics.Process.Start("shutdown.exe", "-s -t 300")
  1. October 27th, 2009 at 06:53 | #1

    by using above code my system not getting shutdown or restart instead its creating new child form

  2. Sam
    December 14th, 2009 at 04:11 | #2

    I tried this line of code in my C# compiler, and when used both in debug and the exe, nothing happened other than CMD flashing up for a split second. No shutdown occurred.

  3. mojo
    June 23rd, 2010 at 10:47 | #3

    because it is
    System.Diagnostics.Process.Start

  1. No trackbacks yet.
You must be logged in to post a comment.