How to add the BUILTIN \\ Administrators group in SQL Server to non-English operating systems?

3

During the installation of my application on a server, the following line is executed:

using (var com = con.CreateCommand())
{
    com.CommandText = "CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS";
    com.ExecuteNonQuery();
}

This code works fine when run on English operating systems, but when I tried to run on a Portuguese OS it did not work.

What would be the correct command, so that this code can run on any operating system, regardless of language?

    
asked by anonymous 19.05.2016 / 15:03

1 answer

3

I was able to resolve this problem as follows:

For known groups, such as Administrators and Guests, you can retrieve the name based on the Secutiry Identifier (SID). A list of known SIDs is available here :

For this specific case, the Administrators group has the SID="S-1-5-32-544". So, here's the final solution:

string sidBuiltinAdmins = "S-1-5-32-544";
string builtinAdmins = new System.Security.Principal.SecurityIdentifier(sidBuiltinAdmins).Translate(typeof(System.Security.Principal.NTAccount)).ToString();
using (var com = con.CreateCommand())
{
    com.CommandText = string.Format("CREATE LOGIN [{0}] FROM WINDOWS", builtinAdmins);
    com.ExecuteNonQuery();
}
    
19.05.2016 / 16:45