同上。

解决方案 »

  1.   

    试试GetUserObjectInformation和GetUserObjectSecurity这两个函数。
      

  2.   

    给你一个源代码。最初的代码好像是yuange编的,不记得了。从绿盟那儿得的。我改了改,能够显示组信息。// whoami.cpp
    // cl whoami.cpp /c1 /c
    // link whoami.obj /nodefaultlib msvcrt.lib advapi32.lib kernel32.lib /align:16
    //
    //
    //#pragma comment(lib,"Advapi32.lib")#include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <Windows.h>#define UULEN 256
    int main(int argc,char *argv[])
    {
        //OpenProcess();
        HANDLE hp , htoken;
        char buff[2560];
        unsigned long size = 2560;    TOKEN_USER *tuser;
    PTOKEN_GROUPS tgroup;
    PTOKEN_OWNER towner;
    PTOKEN_SOURCE tsource;
        PSID sid;
        char user[UULEN], domain[UULEN];
        SID_NAME_USE snu;    hp = htoken = INVALID_HANDLE_VALUE;
        hp = GetCurrentProcess();    if(!OpenProcessToken(hp, TOKEN_QUERY | TOKEN_QUERY_SOURCE , &htoken))
        {
            printf("OpenProcessToken error : %u\r\n", GetLastError());
            goto exit_main;
        }
        if(!GetTokenInformation(htoken, TokenUser, (void*)buff, size, &size))
        {
            printf("GetTokenInformation error : %u\r\n", GetLastError());
            goto exit_main;
        }
        tuser = (TOKEN_USER*)buff;
        sid = tuser->User.Sid;
        size = UULEN;
        if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
        {
            printf("LookupAccountSid error : %u\r\n", GetLastError());
            goto exit_main;
        }
    //    printf("you are '%s\\%s'\r\n", domain, user);
    printf( "Domain  : %s\nUser    : %s\n", domain, user); size = UULEN *10;
        if(!GetTokenInformation(htoken, TokenGroups , (void*)buff, size, &size))
        {
            printf("GetTokenInformation error : %u\r\n", GetLastError());
            goto exit_main;
        }
        tgroup = (PTOKEN_GROUPS)buff;
        int len ;
    len = tgroup->GroupCount;
    printf( "Group   :\n");
    int i;
    for( i = 0; i< len ; i++) 
    {
    sid = tgroup->Groups[i].Sid ;
    size = UULEN;
    if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
    {
    // printf("LookupAccountSid error : %u\r\n", GetLastError());
    break;
    }
    printf("\t[%d] %s\n",i+1, user );
    } size = 2560;    if(!GetTokenInformation(htoken, TokenOwner, (void*)buff, size, &size))
        {
            printf("GetTokenInformation error : %u\r\n", GetLastError());
            goto exit_main;
        } towner = (PTOKEN_OWNER)buff;
        sid = towner->Owner;
        size = UULEN;    if(!LookupAccountSid(NULL, sid, user, &size, domain, &size, &snu))
        {
            printf("LookupAccountSid error : %u\r\n", GetLastError());
            goto exit_main;
        } printf( "Owner   : %s\n", user ); size = 2560;    if(!GetTokenInformation(htoken, TokenSource, (void*)buff, size, &size))
        {
            printf("GetTokenInformation error : %u\r\n", GetLastError());
            goto exit_main;
        }
    tsource = (PTOKEN_SOURCE ) buff;
        tuser = (TOKEN_USER*)buff;
        sid = tuser->User.Sid;
        size = UULEN; printf( "Source  : %.8s\n", tsource->SourceName );
    exit_main:
        if(htoken != INVALID_HANDLE_VALUE)CloseHandle(htoken);
        if(hp != INVALID_HANDLE_VALUE)CloseHandle(hp);
        return 0;
    }
      

  3.   

    BOOL GetUserObjectInformation(
      HANDLE hObj,            // handle to object
      int nIndex,             // type of information to retrieve
      PVOID pvInfo,           // information buffer
      DWORD nLength,          // size of the buffer
      LPDWORD lpnLengthNeeded // receives required buffer size
    );