本文主要是介绍windows 获取当前用户的sid,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
windows 获取当前用户的sid
1)cmd命令查询
2)代码获取
char userName[MAX_NAME] = "";
char sid[MAX_NAME] = "";
DWORD nameSize = sizeof(userName);
GetUserName((LPWSTR)userName, &nameSize);char userSID[MAX_NAME] = "";
char userDomain[MAX_NAME] = "";
DWORD sidSize = sizeof(userSID);
DWORD domainSize = sizeof(userDomain);SID_NAME_USE snu;
LookupAccountName(NULL,
(LPWSTR)userName,
(PSID)userSID,
&sidSize,
(LPWSTR)userDomain,
&domainSize,
&snu);PSID_IDENTIFIER_AUTHORITY psia = GetSidIdentifierAuthority(userSID);
sidSize = sprintf(sid, "S-%lu-", SID_REVISION);
sidSize += sprintf(sid + strlen(sid), "%-lu", psia->Value[5]);int i = 0;
int subAuthorities = *GetSidSubAuthorityCount(userSID);for (i = 0; i < subAuthorities; i++)
{
sidSize += sprintf(sid + sidSize, "-%lu", *GetSidSubAuthority(userSID, i));
}
这篇关于windows 获取当前用户的sid的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!