Advertisement

07.22.2008 at 01:59AM PDT, ID: 23584451
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.8

Shutting down Windows XP - AdjustTokenPrivileges failing with error code 1300

Asked by Sanx69 in Microsoft Visual Basic.Net, Windows Programming, .NET Framework 2.x

Tags: ,

I'm writing a very simple shell application and it needs to be able to reboot or shutdown the operating system; in this case, Windows XP SP2. The shell will be run in a standard user context - with no administrative rights.

Currently, when the code is run with EWX_SHUTDOWN or EWX_REBOOT flags passed to the DoExitWindows subroutine, absolutely nothing happens. Passing EWX_LOGOFF succesfully logs the user off.

When a reboot or shutdown is attempted, AdjustTokenPrivileges returns error 1300 - "Not all privileges referenced are assigned". After that, any attempt at calling ExitWindowsEx returns error 87 - "Invalid parameter".

Has anyone got any ideas?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
Const SE_PRIVILEGE_ENABLED As Integer = &H2
Const TOKEN_QUERY As Integer = &H8
Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
Const SE_SHUTDOWN_NAME As String = "SeShutdownPrivilege"
Const EWX_LOGOFF As Integer = &H0
Const EWX_SHUTDOWN As Integer = &H1
Const EWX_REBOOT As Integer = &H2
Const EWX_FORCE As Integer = &H4
Const EWX_POWEROFF As Integer = &H8
Const EWX_FORCEIFHUNG As Integer = &H10
 
Friend Structure Luid
    Public Count As Integer
    Public Luid As Long
    Public Attr As Integer
End Structure
 
Private Declare Function GetCurrentProcess Lib "kernel32.dll" () As IntPtr
 
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal h As IntPtr, ByVal acc As Integer, ByRef phtok As IntPtr) As Boolean
 
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal host As String, ByVal name As String, ByRef pluid As Long) As Boolean
 
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal htok As IntPtr, ByVal disall As Boolean, ByRef newst As Luid, ByVal len As Integer, ByVal prev As IntPtr, ByVal relen As IntPtr) As Boolean
 
Private Declare Function ExitWindowsEx Lib "user32.dll" (ByVal flg As Integer, ByVal rea As Integer) As Boolean
 
Private Sub DoExitWindows(ByVal flg As Integer)
    Dim tp As Luid
    Dim hproc As IntPtr = GetCurrentProcess()
    Dim htok As IntPtr = IntPtr.Zero
 
    OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES Or TOKEN_QUERY, htok)
    tp.Count = 1
    tp.Luid = 0
    tp.Attr = SE_PRIVILEGE_ENABLED
 
    LookupPrivilegeValue(Nothing, SE_SHUTDOWN_NAME, tp.Luid)
 
    AdjustTokenPrivileges(htok, False, tp, 0, IntPtr.Zero, IntPtr.Zero)
 
    ExitWindowsEx(flg, 0)
 
End Sub
 
Loading Advertisement...
 
[+][-]07.22.2008 at 08:12AM PDT, ID: 22060288

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 04:14PM PDT, ID: 22064554

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:03PM PDT, ID: 22065453

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.22.2008 at 07:17PM PDT, ID: 22065503

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 07:44PM PDT, ID: 22085563

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:12PM PDT, ID: 22085743

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, Windows Programming, .NET Framework 2.x
Tags: VB.NET, AdjustTokenPrivileges and ExitWindowsEx
Sign Up Now!
Solution Provided By: Sanx69
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.24.2008 at 08:23PM PDT, ID: 22085780

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 08:35PM PDT, ID: 22085817

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2008 at 09:35PM PDT, ID: 22086000

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628