Re: ExitWindowsEx function not working.
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Tue, 13 Jun 2006 03:38:53 GMT
Hi cj,
Thanks for your post!
Regarding Win32 programming, you should always check the API return value
to determine if the API calling fails. Once the API fails, we can use
Marshal.GetLastWin32Error() method to get the Win32 error code. With
searching this error code in errlook.exe, you can get the description text
of the error.
Note: errlook.exe is a tool followed with VS2005/VS.net2003. You can type
errlook.exe in "Visual Studio 2005 Command Prompt" to run the tool.
You should modify the code snippet as below:
Private Declare Auto Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags
As Int32, ByVal dwreserved As Int32) As Int32
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim retval As Int32
retval = ExitWindowsEx(2 + 4, 0)
If (retval = 0) Then
MessageBox.Show(System.Runtime.InteropServices.Marshal.GetLastWin32Error().T
oString())
End If
End Sub
With running, you will get error code 1314, which standards for "A required
privilege is not held by the client." in errlook.exe. With MSDN, you will
see that to shut down or restart the system, the calling process must use
the AdjustTokenPrivileges function to enable the SE_SHUTDOWN_NAME
privilege. This is why our calling will fail.
Note: most of the privilege is disabled for the user account by default.
You have to use AdjustTokenPrivileges to enable it explicitly.
The KB provided by Patrice has demonstrating the correct way of calling
ExitWindowsEx. You may give it a try.
Hope this helps!
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- Follow-Ups:
- References:
- ExitWindowsEx function not working.
- From: cj
- Re: ExitWindowsEx function not working.
- From: cj
- ExitWindowsEx function not working.
- Prev by Date: Re: VB.NET equivalent to "classic" VB "DoEvents"
- Next by Date: Tokenizing
- Previous by thread: Re: ExitWindowsEx function not working.
- Next by thread: Re: ExitWindowsEx function not working.
- Index(es):