Reputation: 170519
In my C# code I want to add a user to "Administrators" group. I've heard that on German version of Windows that group would be called "Administratoren" and perhaps on other local versions it would have other names.
My code passes a hard-coded string when doing the search:
var context = new PrincipalContext( ContextType.Machine );
var group = GroupPrincipal.FindByIdentity( context, "Administrators" );
and so it will break if the group actually has some other name. I've found this MSDN article with well-known SIDs nut I don't get how to actually use them to solve my problem.
How do I locate a local group independent of the Windows OS language?
Upvotes: 4
Views: 776
Reputation: 216333
I don't know if this could be of help.
using System.Security;
using System.Security.Principal;
......
SecurityIdentifier sid = new SecurityIdentifier("S-1-5-32-544");
string name = sid.Translate(typeof(NTAccount)).Value;
Console.WriteLine(name);
the result is
"BUILTIN\Administrators"
I have taken the SID from this page where you can find other values to experiment.
Upvotes: 4