Shutdown/Reset/Log Off PC via VB.NET code?

Hi Mike,
First of all, create a form in vb.net and then insert a button on the form. For the button's onclick event, write the following code:
Private Sub btnoff_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnoff.Click
Process.Start("Shutdown")
End Sub
John
John,
Thanks for post, but your code has some error because it's not working; review your code.
Hi,
There is missing code in the post above; the correct code is here. On the button's click event write following code:
System.Diagnostics.process.start("shutdown" ,"-s -t 00")
Here, -s is for shutdown. If we don't write " -t 00", it will take 20 seconds and then shutdown. To come out of this problem we use this -t for time and 00 is the number of seconds. You can give a maximum of 99 seconds.
Tell me about LOG OFF as well as Restart code and how to do this.
For reset computer:
System.Diagnostics.process.start("shutdown" ,"-r -t 00")
For Log off:
System.Diagnostics.process.start("shutdown" ,"-l -t 00")
M,Hafeez
Hi Mike,
You can automate this process by use of Timer control.
Give all the coding in the timer tick event (the user will give hours and minutes as input in text boxes,;when time is over the computer will automatically shutdown. Here is the code for the timer tick event:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
'Timer1.Enabled = True
Timer1.Start()
s = s + 1
If s = 60 Then
s = 0
m = m + 1
ProgressBar1.Value = ProgressBar1.Value + 1
End If
If m = 60 Then
h= h + 1
m = 0
End If
Txth.Text = h
txtm.Text = m
txts.Text = s
Dim totalhour As Integer = nboxh.Value
Dim totalmint As Integer = nboxm.Value
totalhour = totalhour * 60
Dim totalTime = totalhour + totalmint
Dim offtime As Integer = h * 60 + m
If offtime = totalTime Then
count += 1
off()
End If
End Sub
Public Sub off()
If count = 1 Then
Me.Show()
MsgBox("Your PC Going to Shutdown", MsgBoxStyle.OkOnly)
Process.Start("Shutdown", "/s")
End If
End Sub