title: Get name of LocalGroup Windows C++ using SID
body: <p>I'm trying to get the name of a group regarding the SID of the group. The SID of the local admin group is <strong>S-1-5-32-544</strong> for example. I use the function <strong>ConvertStringSidToSid</strong> and <strong>LookupAccountSid</strong> to get the name of the group Administrator, but the function return 0.</p>
  
  <p>Any advice on this ?</p>
  
  <pre><code>#ifndef UNICODE
  #define UNICODE
  #endif 
  
  #include &lt;windows.h&gt;
  #include &lt;lmcons.h&gt;
  #include &lt;lmaccess.h&gt;
  #include &lt;lmerr.h&gt;
  #include &lt;lmapibuf.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;Sddl.h&gt;
  #include &lt;string&gt;
  
  #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"), &amp;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, &amp;psid, buffName, &amp;buffNameSize, NULL, &amp;buffDomainSize, &amp;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);
  }
  </code></pre>
  
  <p>I get the following error :</p>
  
  <blockquote>
    <p>Error code: 87
    The parameter is incorrect.</p>
  </blockquote>