|
-
Jun 8th, 2006, 01:19 PM
#1
Thread Starter
Lively Member
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.
-
Jun 8th, 2006, 01:34 PM
#2
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
-
Jun 8th, 2006, 07:22 PM
#3
Re: VB.NET Shutdown fails to execute in WindowsXP
try this:
VB Code:
Process.Start("Shutdown -s -t 05")
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jun 10th, 2006, 10:18 AM
#4
Fanatic Member
Re: VB.NET Shutdown fails to execute in WindowsXP
Last edited by TokersBall_CDXX; Jun 10th, 2006 at 10:49 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|