龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

查看进程令牌信息源代码(2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
源程序 /** TokenInfor tell Token Infor and Owner Infor of Specify Process --bingle, bingle@email.com.cn */ #include #include #include #include #define UULEN 256 #define true 1 #define false 0 typed

源程序
/**
TokenInfor tell Token Infor and Owner Infor of Specify Process
--bingle, bingle@email.com.cn
*/

#include
#include
#include
#include

#define UULEN 256
#define true 1
#define false 0

typedef DWORD GetModuleFileNameExType(
HANDLE hProcess, // handle to the process
HMODULE hModule, // handle to the module
LPTSTR lpFilename, // buffer that receives the path
DWORD nSize // size of the buffer
);
GetModuleFileNameExType *GetModuleFileNameExAddr;
HMODULE psapi;

int GetUserNameFromToken(HANDLE htoken, char user[]);
int OutPutGroupsFromToken(HANDLE htoken);
int OutPutPrivilegesFromToken(HANDLE htoken);
int OutPutTokenType(TOKEN_STATISTICS *tstat);
int GetProcessTokenSource(HANDLE hp, char src[]);
int EnableDebugPriv(int fEnable);

void Usage(char *prog)
{
printf(" Usage : [pid] ", prog);
printf(" pid -- ID of target process, if not provide, use current process ");
printf(" -?|/? -- show this. ");

exit(0);
}

int LoadPsapi()
{
psapi = LoadLibrary("psapi.dll");
GetModuleFileNameExAddr = NULL;
if(psapi == NULL) return 0;
GetModuleFileNameExAddr = (GetModuleFileNameExType*)GetProcAddress(psapi, "GetModuleFileNameExA");
if(GetModuleFileNameExAddr == NULL)
{
psapi = NULL;
return 0;
}
return 1;
}

int main(int argc,char *argv[])
{
printf("TokenInfor tell Token Infor and Owner Infor of Specify Process, -- bingle ");
if(argc == 2 && strcmp(argv[1], "/?") == 0)Usage(argv[0]);
if(argc == 2 && strcmp(argv[1], "-?") == 0)Usage(argv[0]);

HANDLE hp , htoken;
char buff[1024];
unsigned long size = 1024, ret, procID;

精彩图集

赞助商链接