Shutdown, Restart, or Log Off your computer using VB.Net

 

I made the name property for these buttons to (name=btnShutdown, btnRestart, btnLogOff, and btnExit) that is to help us using and calling the buttons in the code.

But what about the procedure that will make me do the shutdown process

well we write this in the code for each button:

first we write function that will call the shutdown procedure: System.Diagnostics.Process.Start

Then we call the shutdown procedure: (“shutdown”,

after we called it we will have to name the process we want to do:

to make it shutdown: we write after the comma “-s”

and to make it restart we write after the comma “-r”

and to make it logoff we write after the comma “-l”

so the code will be for example:

System.diagnostics.Process.Start(“shutdown”, “-s”)

‘ Will cause the computer to shutdown

but when you order it to shutdown like this it will give you about 20 sec to shutdown

but there is a way to manage that

System.Diagnostics.Process.Start(“shutdown”, “-s -t 00”)

‘ The -t will contol the time after -t we write the number of sec (Note: max sec = 99)

Now we make for each one of the buttons its own sub (simply we can do that by double clicking on each button)

The code for the whole program will be as follows

Public Class frmShutdown

Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click

System.Diagnostics.Process.Start(“shutdown”, “-s -t 00”)

‘This will make the computer Shutdown

End Sub

Private Sub btnRestart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRestart.Click

System.Diagnostics.Process.Start(“shutdown”, “-r -t 00”)

‘This will make the computer Restart

End Sub

Private Sub btnLogOff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOff.Click

System.Diagnostics.Process.Start(“shutdown”, “-l -t 00”)

‘This will make the computer Log Off

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

<span style="color:#008000;"

Leave a comment