Error 977 from LookupPrivilegeValue

This is a discussion on Error 977 from LookupPrivilegeValue within the Windows Programming forums, part of the Platform Specific Boards category; Hi I'm trying to set a privilege value, but LookupPrivilegeValue returns error code 997, from GetLastError() Code: Code: DWORD eh ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92

    Error 997 from LookupPrivilegeValue

    Hi
    I'm trying to set a privilege value, but LookupPrivilegeValue returns error code 997, from GetLastError() Code:
    Code:
    DWORD eh = GetLastError();
    SetLastError(0);
    HANDLE tokenHandle;
    TOKEN_PRIVILEGES tp;
    LUID luid;
    
    if (GetVersion() >= 0)
    	{
    		if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &tokenHandle))
    		{
    			eh = GetLastError();
    			MessageBox(NULL, "Error opening process token", "Error", MB_OK);
    			return false;
    		}
    		eh = GetLastError();
    		if (!LookupPrivilegeValue(NULL, "SeDebugPrivilege", &luid))
    		{
    			eh = GetLastError();
    			MessageBox(NULL, "Error looking up privilege", "Error", MB_OK);
    			return false;
    		}
    		tp.Privileges->Luid = luid;
    		eh = GetLastError();	
    		tp.PrivilegeCount = 1;
    		tp.Privileges->Attributes = SE_PRIVILEGE_ENABLED;
    		if (!AdjustTokenPrivileges(tokenHandle, false, &tp, 0, 0, 0))
    		{
    			eh = GetLastError();
    			MessageBox(NULL, "Error adjusting token", "Error", MB_OK);
    		}
    	}
    Does anyone knows whats wrong here?

    Thanks in advance

    The Wazaa
    Last edited by The Wazaa; 02-23-2006 at 12:45 AM.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Error 977 Is not documented, confusing

  3. #3
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    How embarrasing, I ment 997 :-S. It kinda works now, I get access to the process but I think that it still returns 997.

    Thanks for the reply

    The Wazaa

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Where does the error occur now? Still LookupPrivilegeValue?

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    Yes, but now I'm able to use OpenProcess with all access, so that part works.

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You can't call GetLastError in the middle of nowhere and expect a useful result. A recent post:
    Quote Originally Posted by anonytmouse
    You can only rely on the return value of GetLastError when:
    • You have just called a WinAPI function (there can be no calls to other functions in between the original call and the call to GetLastError).
    • The return value of the function indicates it has failed.
    • The function is documented to provide a GetLastError value.

    At other times, the GetLastError value is not useful.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    okay, I see thanks

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21