Adding Local User to Local Admin Group

后端 未结 2 655
隐瞒了意图╮
隐瞒了意图╮ 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:11

    You mention that these machines are on a domain, it is much simpler to just do this with group policy.

    Go in to group policy management (gpmc.msc) and create a new policy. Once you have a new policy created go to Computer Configuration->Prefrences->Local Users and Groups.enter image description here

    From there right click and go to New->Local User. In the new screen set the action to Create (you can click the help button to see the difference between the modes) and enter your info for the user in that screen.

    enter image description here

    One you click ok the user will show up on the screen on the local users and groups page. From there right click and go to New->Local Group. On the new page set the action to Update, use the drop-down to find the group name Administrators (built-in) and select it. In the bottom section click Add... and type in by hand the same name you put in from the previous screen (itadmin in your case). At the end it should look like this

    enter image description here

    the Local Users and Groups page will look like this

    enter image description here

    It is important to notice the Order column, the update on the administrator's group must have a higher order number than the user creation command.

    One you have your group policy set up apply the policy to the machines that are in the lab (be it through OU targeting or Security Filtering, or WMI Filtering). On next reboot the local itadmin user will be created on each machine.


    Also a interesting note, when you choose the user when selecting who to add to the local administrators group, you can click the ... and choose a user on the domain this will allow someone to use their domain login to be a local admin on a small set of computers without giving them rights to be a admin everywhere. However they will need to be able to log in using the domain for this to work, so if you are troubleshooting a network connectivity issue your current approach may be a better thing to do.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题