We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Create windows User Using C#

rajputamitd
rajputamitd asked
on
Medium Priority
2,389 Views
Last Modified: 2013-12-17
Hi

I am using VS2008.How can we create windows user Using C#.net
Comment
Watch Question

CERTIFIED EXPERT

Commented:
try this
some resources are here
HTH
i

DirectoryEntry adRoot = new DirectoryEntry(LDAP://OU=users,DC=alpha,DC=fr, null, null);
// or DirectoryEntry adRoot = new DirectoryEntry(LDAP://OU=users,DC=alpha,DC=fr, admin, P@ssWord);
 
DirectoryEntry user = adRoot.Children.Add(cn= + login +   + givName, user);
 
user.Properties["SAMAccountName"].Add(SAMAccount);
user.Properties["sn"].Add(login);
user.Properties["givenName"].Add(givName);
user.Properties["description"].Add(desc);
user.Properties["userPrincipalName"].Add(sAMAccount + @ALPHA.FR);
 
user.CommitChanges();
user.Invoke(SetPassword, P@ssWord);
 
user.Properties["userAccountControl"].Value = 0Ă—0200;
// http://support.microsoft.com/kb/305144
 
user.CommitChanges();

Open in new window

Author

Commented:
Can u pls agian give the code.Pls ensure that formatting doesn't change.

Author

Commented:
Ok here is the code which I have used and is working accordingly.
But it works only for .Net Framework 3.5

using System.DirectoryServices.AccountManagement;
 
PrincipalContext pc = new PrincipalContext(ContextType.Machine);
System.DirectoryServices.AccountManagement.UserPrincipal u = new UserPrincipal(pc);
u.SetPassword(password);
u.Name = username;
//u.Description = description;
u.UserCannotChangePassword = true;
u.PasswordNeverExpires = true;
u.Save();
this.label4.Text = "New User Has been Created";
CERTIFIED EXPERT
Commented:
so it's ok?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Yes it is fine.It is working well.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.