Help on Shutting down a computer...

MykelV

New member
Joined
Jun 24, 2004
Messages
2
Programming Experience
Beginner
hi, i need help on how to shutdown a computer using vb.net, i tried using the code below but it doesnt seem to work. it will only log-off a computer, i want it to shutdown. i hope you guys can help me. tnx.

Public Class Form1

Inherits System.Windows.Forms.Form

Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Integer, ByVal dwReserved As Integer) As Integer

Public Const EWX_POWEROFF As Short = 0





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim lresult As Object

lresult = ExitWindowsEx(EWX_POWEROFF, 0)

End Sub

End Class
 

vbkev

Active member
Joined
Jun 4, 2004
Messages
32
Location
Newcastle, UK
Programming Experience
5-10
Public Const EWX_SHUTDOWN = 1

Public Const EWX_REBOOT = 2

Public Const EWX_FORCE = 4


'to reboot machine, forcing any open programs to close
lresult = ExitWindowsEx(EWX_FORCE Or EWX_REBOOT, 0)

'to shutdown machine, forcing any open programs to close
lresult = ExitWindowsEx(EWX_FORCE Or EWX_SHUTDOWN, 0)

 
Top Bottom