Categories

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna, tincidunt vitae molestie nec, molestie at mi. Nulla nulla lorem, suscipit in posuere in, interdum non magna.

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")

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

Leave a Reply