Quantcast
Channel: API Programming »» XP « API Programming
Viewing all articles
Browse latest Browse all 3

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

$
0
0

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

Viewing all articles
Browse latest Browse all 3

Trending Articles