TranslateName() function doesn’t work on win10

my working computer is win10, and I am using vs2015, now I’ve met a weird issue. I can get the NameSamCompatible name by the following source code:

const int UNLEN = 100;
TCHAR Username[UNLEN + 1];
DWORD nULen = UNLEN;
GetUserNameEx(NameSamCompatible, Username, &nULen);

the Username would be “PROD\wwu2”, but I would get failed if I run:

char trans_name[100];
ULONG ulSize = 100;
BYTE n = TranslateName(Username, NameSamCompatible, NameDnsDomain, trans_name, &ulSize);

then I get the error code by GetLastError(); it is 1317(user doesn’t exist). but the username is the one I got by GetUserNameEx, I didn’t change anything.

the whole source code is:

#include "stdafx.h"

#include <Windows.h>
#include <sspi.h>
#include <secext.h>
#include <ntdsapi.h>

int main()
{
const int UNLEN = 100;
TCHAR Username[UNLEN + 1];
DWORD nULen = UNLEN;

GetUserNameEx(NameSamCompatible, Username, &nULen);


char trans_name[100];
ULONG ulSize = 100;

BYTE n = TranslateName(Username, NameSamCompatible, NameDnsDomain, trans_name, &ulSize);

int c = GetLastError();
return 0;
}

Leave a Comment