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

Asked By 220 points N/A Posted on -
qa-featured

Does anyone know how to terminate a process using Vb.net like shutdown?

Help me if any one can.

SHARE
Best Answer by John peter
Best Answer
Best Answer
Answered By 110 points N/A #88139

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

qa-featured

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

Answered By 220 points N/A #88140

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

qa-featured

John,

Thanks for post, but your code has some error because it's not working; review your code.

Answered By 0 points N/A #88141

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

qa-featured

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.

Answered By 220 points N/A #88142

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

qa-featured

Tell me about LOG OFF as well as Restart code and how to do this.

Answered By 0 points N/A #88143

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

qa-featured

For reset computer:

System.Diagnostics.process.start("shutdown" ,"-r -t 00")

For Log off:

System.Diagnostics.process.start("shutdown" ,"-l -t 00")

M,Hafeez

Answered By 110 points N/A #88144

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

qa-featured

Hi Mike,

You can automate this process by use of Timer control.

  1. Create a form and draw two text boxes – one for Minutes and one for Hours  and control via the timer tick event.

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

Answered By 220 points N/A #88145

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

qa-featured

Thanks guys. All of you,

Thanks for supporting me.

Related Questions