LsaEnumerateTrustedDomains错误
以下代码运行时出现错误 8478(要求的操作需要一个目录服务,但没有可用的)
请高人指点,是什么原因,先谢谢了
#include "stdlib.h"
#include "stdafx.h"
#include <Windows.h>
#include "Ntsecapi.h"
#define TARGET_SYSTEM_NAME L"xxxx"
//xxxx:我的计算机名
LSA_HANDLE GetPolicyHandle();
int main(int argc, char* argv[])
{
LSA_HANDLE hLsa = GetPolicyHandle();
PLSA_TRUST_INFORMATION plsaInfo = NULL;
LSA_ENUMERATION_HANDLE hEnum;// = NULL;
memset(&hEnum,0,sizeof(LSA_ENUMERATION_HANDLE));
ULONG rcount = 0;
NTSTATUS rst = LsaEnumerateTrustedDomains(hLsa,&hEnum,(void**)&plsaInfo,2,&rcount);
ULONG errcode = LsaNtStatusToWinError(rst);
printf("ERROR CODE:%u\n",errcode);
system("PAUSE");
return 0;
}
LSA_HANDLE GetPolicyHandle()
{
LSA_OBJECT_ATTRIBUTES ObjectAttributes;
WCHAR SystemName[] = TARGET_SYSTEM_NAME;
USHORT SystemNameLength;
LSA_UNICODE_STRING lusSystemName;
NTSTATUS ntsResult;
LSA_HANDLE lsahPolicyHandle;
// Object attributes are reserved, so initialize to zeroes.
ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
//Initialize an LSA_UNICODE_STRING to the server name.
SystemNameLength = wcslen(SystemName);
lusSystemName.Buffer = SystemName;
lusSystemName.Length = SystemNameLength * sizeof(WCHAR);
lusSystemName.MaximumLength= (SystemNameLength+1) * sizeof(WCHAR);
// Get a handle to the Policy object.
ntsResult = LsaOpenPolicy(
&lusSystemName, //Name of the target system.
&ObjectAttributes,
POLICY_ALL_ACCESS, //Desired access permissions.
&lsahPolicyHandle //Receives the policy handle.
);
return lsahPolicyHandle;
}