?
Solved

Create windows User Using C#

Posted on 2009-02-10
5
Medium Priority
?
2,316 Views
Last Modified: 2013-12-17
Hi

I am using VS2008.How can we create windows user Using C#.net
0
Comment
Question by:rajputamitd
  • 3
  • 2
5 Comments
 
LVL 22

Expert Comment

by:Ivo Stoykov
ID: 23608749
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

0
 

Author Comment

by:rajputamitd
ID: 23608794
Can u pls agian give the code.Pls ensure that formatting doesn't change.
0
 

Author Comment

by:rajputamitd
ID: 23608973
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";
0
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 1500 total points
ID: 23610627
so it's ok?
0
 

Author Comment

by:rajputamitd
ID: 23619464
Yes it is fine.It is working well.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question