Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8921247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:29:28+00:00 2026-06-15T06:29:28+00:00

I am trying to create a domain user and then add them to local

  • 0

I am trying to create a domain user and then add them to local groups on the current machine. Every time I do this when I call add on the domain I get this {"A member could not be added to or removed from the local group because the member does not exist.\r\n"}. However I know the user exists as my tester was watching the directory and as soon as my create code ran the user showed up.

I will say that I noticed when I translate the SID to an NTUser account I end up with domain\$DDDDD-FAF234AFS as the name instead of a domain\test.user. Why is that hapening and is that my problem maybe?

Here is my code to create a user:

private UserPrincipal CreateNewUser(Section.User.User user, PrincipalContext principal)
    {
        _logger.Debug("User did not exist creating now.");
        UserPrincipal newUser = new UserPrincipal(principal)
            {
                Name = user.UserName.Contains('\\') ? user.UserName.Split('\\')[1] : user.UserName,
                Description = string.IsNullOrEmpty(user.UserDescription) ? "IIS {0} user.".FormatWith(user.UserType) : user.UserDescription,
                UserCannotChangePassword = false,
                PasswordNeverExpires = true,
                PasswordNotRequired = false,
                Enabled = true
            };
        _logger.Debug("User created.");

        _logger.Debug("Setting user password and applying to the system.");
        newUser.SetPassword(user.UserPassword);
        newUser.Save();

        return newUser;
    }

The user is just a custom class with username, password, and description. The principalcontext is a valid context for the domain.

Here is the code I use to add the user to local domains:

private void AddDomainUserToGroup(Principal groupPrincipal, Principal user, string group)
    {
        using (DirectoryEntry groupEntry = groupPrincipal.GetUnderlyingObject() as DirectoryEntry)
        using (DirectoryEntry userEntry = user.GetUnderlyingObject() as DirectoryEntry)
        {
            NTAccount ntUser = user.Sid.Translate(typeof (NTAccount)) as NTAccount;
            string domain = ntUser.ToString().Split('\\')[0];
            string userPath = string.Format("WinNT://{0}/{1},user", domain, user);

            groupEntry.Invoke("Add", new object[] {userPath});
        }
    }

Also I have never added the user to the local machine I just add them to the domain. Is that my problem maybe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:29:29+00:00Added an answer on June 15, 2026 at 6:29 am

    I figured this out and in case anyone else has similar problems here is my solution. Basically it was failing because I never set the samAccountname oonce I set that to my username everything worked perfectly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to create a Friendship domain object to link two User objects
I am trying to create 2 domain classes User and MailBox There will be
I am trying to create a validation that checks to make sure a domain/url
Im trying to create a web service which gets to a URL e.g. www.domain.co.uk/prices.csv
I'm trying to create an FTP script that will copy a local folder structure
I'm still learning what hibernate can do and this time i'm trying something that
I'm trying to create a new user on my development active directory server using
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,
Ok so I am trying create a login script, here I am using PHP5

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.