【发布时间】:2016-07-08 14:17:08
【问题描述】:
我正在尝试获取有关组 SID 的组名称。例如,本地管理员组的 SID 是 S-1-5-32-544。我使用函数 ConvertStringSidToSid 和 LookupAccountSid 来获取组管理员的名称,但该函数返回 0。
对此有何建议?
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <lmcons.h>
#include <lmaccess.h>
#include <lmerr.h>
#include <lmapibuf.h>
#include <stdio.h>
#include <stdlib.h>
#include <Sddl.h>
#include <string>
#pragma comment(lib, "netapi32.lib")
#pragma comment(lib, "Advapi32.lib")
static const DWORD MAX_BUFF_SIZE = 256;
std::wstring userNameFromSid()
{
PSID psid;
BOOL bSucceeded = ConvertStringSidToSid(TEXT("S-1-5-11"), &psid);
if (bSucceeded == FALSE) {
printf("Error Converting SID to String");
}
wchar_t buffName[MAX_BUFF_SIZE];
DWORD buffNameSize = MAX_BUFF_SIZE;
wchar_t buffDomain[MAX_BUFF_SIZE];
DWORD buffDomainSize = MAX_BUFF_SIZE;
SID_NAME_USE SidType = SidTypeGroup;
if (LookupAccountSid(NULL, &psid, buffName, &buffNameSize, NULL, &buffDomainSize, &SidType))
{
printf("group name %ws\n", buffName);
return buffName;
}
printf("Error code: %d", GetLastError());
LocalFree(psid);
/*Here some code to print error in a Message box*/
return L"";
}
int main()
{
NET_API_STATUS err = 0;
userNameFromSid();
return(0);
}
我收到以下错误:
错误代码:87 参数不正确。
【问题讨论】:
-
当
LookupAccountSid失败时,GetLastError返回什么? -
您希望如何收到请求的信息?您没有传递任何输出缓冲区,但很有希望,它们的大小都是 1。LookupAccountSid 的文档需要更彻底地阅读。
-
@IInspectable 哼,我编辑代码
-
&psid不正确。 -
有效答案!你可以发布它,我会接受它@ncalmbeblpaicr0011