1

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;
}
  • 1
    It would be helpful, if you post here the GetLastError() value after TranslateName call. Also, are you sure your username is a name of user that is a part of some domain? – Arthur Bulakaiev Mar 12 '19 at 10:41
  • the error code is 1317(user doesn't exist), but the username is the one I got by GetUserNameEx, I didn't change anything. – winnie_quest Mar 13 '19 at 01:20
  • by the way, I've also tried the api: DsCrackNames and IADsNameTranslate, both can't achieve my purpose, I want to converse my domain name from nt4 domain name to dns domain name (PROD\wwu2 -> prod.company.com\wwu2), but those two apis doesn't support dns domain name format – winnie_quest Mar 13 '19 at 06:41

0 Answers0