Pregunta

en una pregunta anterior pregunté cómo superar el hecho de que en ciertos usuarios los privilegios de depuración no estaban allí. Ahora, dado que no puedo configurar algo que no existe, ¿cómo verificaría si un usuario tiene privilegios de depuración?

Sé que tengo que usar LookupPrivilegeValue (), simplemente no puedo entender dónde leer el valor devuelto que indicaría si existe o no un privilegio particular.

El código es apreciado.

Gracias

¿Fue útil?

Solución

De http://msdn.microsoft. com / es-us / library / aa446619% 28VS.85% 29.aspx

BOOL SetPrivilege(
    HANDLE hToken,          // access token handle
    LPCTSTR lpszPrivilege,  // name of privilege to enable/disable
    BOOL bEnablePrivilege   // to enable or disable privilege
    ) 
{
    TOKEN_PRIVILEGES tp;
    LUID luid;

    if ( !LookupPrivilegeValue( 
            NULL,            // lookup privilege on local system
            lpszPrivilege,   // privilege to lookup 
            &luid ) )        // receives LUID of privilege
    {
        printf("LookupPrivilegeValue error: %u\n", GetLastError() ); 
        return FALSE; 
    }

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    if (bEnablePrivilege)
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    else
        tp.Privileges[0].Attributes = 0;

    // Enable the privilege or disable all privileges.

    if ( !AdjustTokenPrivileges(
           hToken, 
           FALSE, 
           &tp, 
           sizeof(TOKEN_PRIVILEGES), 
           (PTOKEN_PRIVILEGES) NULL, 
           (PDWORD) NULL) )
    { 
          printf("AdjustTokenPrivileges error: %u\n", GetLastError() ); 
          return FALSE; 
    } 

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)

    {
          printf("The token does not have the specified privilege. \n");
          return FALSE;
    } 

    return TRUE;
}

si la función devuelve ERROR_NOT_ALL_ASSIGNED cuando solicita establecer privilegios de depuración, entonces el token no está allí.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top