日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > windows >内容正文

windows

Windows访问令牌相关使用方法

發(fā)布時(shí)間:2023/12/15 windows 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Windows访问令牌相关使用方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

一.OpenProcessToken

打開(kāi)進(jìn)程訪問(wèn)令牌

WINADVAPI BOOL WINAPI OpenProcessToken (__in HANDLE ProcessHandle,__in DWORD DesiredAccess,__deref_out PHANDLE TokenHandle);

二.GetTokenInformation

獲取令牌特定權(quán)限信息

WINADVAPI BOOL WINAPI GetTokenInformation (__in HANDLE TokenHandle,__in TOKEN_INFORMATION_CLASS TokenInformationClass,__out_bcount_part_opt(TokenInformationLength, *ReturnLength) LPVOID TokenInformation,__in DWORD TokenInformationLength,__out PDWORD ReturnLength);

Demo示例

BOOL GetElevationType(HANDLE hProcess, TOKEN_ELEVATION_TYPE* pElevationType) {HANDLE hToken = NULL;// Get current process token if (!OpenProcessToken(hProcess, TOKEN_QUERY, &hToken))return FALSE;BOOL bResult = FALSE;DWORD dwSize = 0;// Retrieve elevation type information BOOL bFlag = GetTokenInformation(hToken, TokenElevationType, pElevationType, sizeof(TOKEN_ELEVATION_TYPE), &dwSize);CloseHandle(hToken);return bFlag; }

?

參考:http://johnny161.blog.163.com/blog/static/9028195201181341417421/

三.IsUserAnAdmin

Tests whether the current user is a member of the Administrator's group.

其是對(duì)CheckTokenMembership的封裝

A SID allocated with the AllocateAndInitializeSid function must be freed by using the FreeSid function.

BOOL IsUserAdmin(VOID) /*++ Routine Description: This routine returns TRUE if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyone and is expected to be able to open its own process and process token. Arguments: None. Return Value: TRUE - Caller has Administrators local group. FALSE - Caller does not have Administrators local group. -- */ { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; PSID AdministratorsGroup; b = AllocateAndInitializeSid(&NtAuthority,2,SECURITY_BUILTIN_DOMAIN_RID,DOMAIN_ALIAS_RID_ADMINS,0, 0, 0, 0, 0, 0,&AdministratorsGroup); if(b) {if (!CheckTokenMembership( NULL, AdministratorsGroup, &b)) {b = FALSE;} FreeSid(AdministratorsGroup); }return(b); }

四.ConvertSidToStringSid

The ConvertSidToStringSid function converts a security identifier (SID) to a string format suitable for display, storage, or transmission.

WINAPI ConvertSidToStringSidW(__in PSID Sid,__deref_out LPWSTR *StringSid);

Sid

A pointer to the SID structure to be converted.

StringSid

A pointer to a variable that receives a pointer to a null-terminated SID string. To free the returned buffer, call the LocalFree function.

總結(jié)

以上是生活随笔為你收集整理的Windows访问令牌相关使用方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。