怎么获取当前用户的权限?(在线等待) 同上。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 试试GetUserObjectInformation和GetUserObjectSecurity这两个函数。 给你一个源代码。最初的代码好像是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 256int 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;} 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); 一个IDL文件如何引用另外一个IDL中的接口定义? CTreeCtrl控件编辑问题 把vc6.0的工程转换到vc2005后,找不到包含的头文件afxwin.h 如何用vc调出powerpoint的画笔的功能 如何选择一个文件夹? 无论是否产生异常,都必须执行的代码如何书写? 如何取字符串中指定位置的字符问题? 基于CView的单文档应用程序如何添加滚动条? 关于VC和SQL的应用? 大家好啊。请多关照 关于在流式套接字使用多线程的问题? VC6.0中的Microsoft Visual Studio\VC98\Bin目录中的cl.exe命令无法用?再线等
// 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;
}
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
);