VB.NET Shutdown fails to execute in WindowsXP
Hello, I have reviewd many of the threads here on how to shutdown a system and created this code using the VB.NET cookbooks solution.
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Private Enum windowsexitflags
logoff = 0
Shutdown = 1
End Enum
Private Sub btnShutdown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShutdown.Click
MessageBox.Show("Test before")'to see if im going through the button press
ExitWindowsEx(windowsexitflags.Shutdown, 1&)
MessageBox.Show(" Test after")
End Sub
Private Sub btnNo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNo.Click
ExitWindowsEx(windowsexitflags.logoff, 0&)
End Sub
Private Sub btnYes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYes.Click
Me.Close()
End Sub
End Class
MY Problem is LOGOFF works, SHUTDOWN does not... I do not understand why. Console app is being run on a windows XP SP2 box under administrative privilges. Any sugestions would be appreciated.
Re: VB.NET Shutdown fails to execute in WindowsXP
it has to do with rights for the code to be allowed to shutdown windows..
here is a VB6 article, but the same idea applies in .NET as well..
http://blogs.msdn.com/brad_mccabe/ar...02/383542.aspx
Re: VB.NET Shutdown fails to execute in WindowsXP
try this:
VB Code:
Process.Start("Shutdown -s -t 05")
Re: VB.NET Shutdown fails to execute in WindowsXP