Adding Local User to Local Admin Group

后端 未结 2 674
隐瞒了意图╮
隐瞒了意图╮ 2020-12-31 09:59

I am writing a C# program to be pushed out the labs I work in. The program is to create a local admin account(itadmin), set the password, set the password to never expire,

2条回答
  •  醉话见心
    2020-12-31 10:12

    For Update 3 (for Multi Language support)

    Please use build in identifiers --> "Well Known SIDs" for build in accounts or groups:

    var sAdministrators = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid , null).Translate(typeof(NTAccount)).Value;
    
    groupPrincipal = GroupPrincipal.FindByIdentity(systemContext, IdentityType.Name, sAdministrators.ToString());
    

    and not: ..... FindByIdentity(systemContext, "Administrators");

    Because if you want to use it "world wide" and outside of the engl. world you will get an error. Example: Germany use "VORDEFINIERT\Administratoren" as Name.

提交回复
热议问题