如何获取管理员组的名称?

时间:2013-07-25 16:48:53

标签: api function winapi windows-xp administrator

我正在寻找一个获得管理员组名称的Windows 32 API函数。当你回答时,请添加一个完整的例子。源代码应该适用于Windows XP及更高版本。

1 个答案:

答案 0 :(得分:3)

您可以使用LookupAccountSid功能执行此操作:

BYTE bBuffer[128];
DWORD dwSize = sizeof(bBuffer);
if (CreateWellKnownSid(WinBuiltinAdministratorsSid, NULL, (PSID)bBuffer, &dwSize))
{
    wchar_t wchName[128], wchDomain[128];
    DWORD cchName = _countof(wchName), cchDomain = _countof(wchDomain);
    SID_NAME_USE use;
    if (LookupAccountSid(NULL, (PSID)bBuffer, wchName, &cchName, wchDomain, &cchDomain, &use))
    {
        // wchDomain will now contain something like BUILTIN
        // wchName will now contain something like Administrators
    }
}