I am looking for a Windows 32 API function which gets the name of the Administrators Group. When you answer, please add a full example. The source code should work with Windows Xp and later.

有帮助吗?

解决方案

You can use the LookupAccountSid function to do that:

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
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top