Question

I have small application that attempts to get SID for a given user on Windows 7 64 bit. The application is compiled as 64 bit.

  PSID         Sid;
  DWORD        cbReferencedDomainName, cbSid;
  LPTSTR       ReferencedDomainName;
  SID_NAME_USE eUse;
  DWORD dwRc = 0;

  printf("Lookup %s\n",lpszAccountName);
  cbReferencedDomainName = cbSid = 0;
  if (LookupAccountName(NULL, lpszAccountName, 0, &cbSid, 
                        0, &cbReferencedDomainName, &eUse)) {
    printf("LookupAccountName passed\n");

    return 0;
  }

  dwRc = GetLastError();
  printf("LookupAccountName RC (%d)\n",dwRc);

I am passing the user name in uid@hostname format. The API fails for every user that's present on the machine with GetLastError returning 1332 - "No mapping between account names and security IDs was done.". Please help.

Was it helpful?

Solution

A colleague and myself revisited this problem. We found that the problem was due to the Character Set used in the Visual Studio Project Settings. Visual Studio by default, sets character set to Use Unicode Character Set. However our application needs to use ASCII character set as our application needs to read input from command line. So the input read from command line was ASCII but we were passing that input to Wide character version of LookupAccountName API i.e. LookupAccountNameW. This caused API to return 1332 error code.

So we changed the Character Set to "Not Set" and recompiled the application. This ensured that correct form of the API, LookupAccountNamA, is used. This resolved the problem. I believe setting Character Set to "" will also solve the problem.

enter image description here

Hope this will be useful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top