c# - Add user account to user-group regardless the O.S language -


in function below, in line use language-specific name "users":

groupprincipal group = groupprincipal.findbyidentity(context, "users"); 

how can language-specific aware?.

i mean example, in language, spanish, group name "usuarios", function throw exception because english name not found.

i liketo able add user administrador, standard users, , guests, without worrying machine current culture language. possibly?.


the function:

public static bool createlocalwindowsaccount(string username, string password, string displayname, string description, bool canchangepwd, bool pwdexpires) {      try     {         principalcontext context = new principalcontext(contexttype.machine);         userprincipal user = new userprincipal(context);         user.setpassword(password);         user.displayname = displayname;         user.name = username;         user.description = description;         user.usercannotchangepassword = canchangepwd;         user.passwordneverexpires = pwdexpires;         user.save();           //now add user "users" group displays in control panel         groupprincipal group = groupprincipal.findbyidentity(context, "users");         group.members.add(user);         group.save();          return true;     }     catch (exception ex)     {         logmessagetofile("error msg" + ex.message);         return false;     }  } 

you can use well-known sid specify group want retrieve. users group sid s-1-5-32-545 using wellknownsidtype enum can avoid putting actual sid code:

var sid = new securityidentifier(wellknownsidtype.builtinuserssid, null); var principal = groupprincipal.findbyidentity(context, identitytype.sid, sid.value); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -