Could you be so nice and give me a code, how could I do that.
Thank you!
> > Good afternoon. Could you help me? I need to create Windows Account
> > Programmatically via C#? How could I do this?
[quoted text clipped - 15 lines]
>
> Willy.
The following has been edited out of a bit of code I use but should work;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
private void CreateUser(string userName, string password)
{
DirectorySearcher dseSearcher = new DirectorySearcher();
string rootDSE = dseSearcher.SearchRoot.Path;
string userDSE = rootDSE.Insert(7, "OU=Users,");
DirectoryEntry userDE = new DirectoryEntry(userDSE);
DirectoryEntry user = userDE.Children.Add("CN=" + userID, "user");
staff.Properties["samAccountName"].Value = userID;
staff.Properties["UserPrincipalName"].Value = userName +
@"@domain";
staff.CommitChanges();
staff.Properties["userAccountControl"].Value =
ActiveDs.ADS_USER_FLAG.ADS_UF_NORMAL_ACCOUNT |
ActiveDs.ADS_USER_FLAG.ADS_UF_DONT_EXPIRE_PASSWD;
staff.CommitChanges();
staff.Invoke("SetPassword", new Object[] { password });
}
for adding a domain account
Tony
> Could you be so nice and give me a code, how could I do that.
>
[quoted text clipped - 19 lines]
> >
> > Willy.
tony lock - 04 Mar 2008 14:46 GMT
Sorry the last 6 lines starting with staff should start with user.
> The following has been edited out of a bit of code I use but should work;
>
[quoted text clipped - 45 lines]
> > >
> > > Willy.
Nikolay Podkolzin - 04 Mar 2008 14:49 GMT
Thank you, guys for your replies. I guess I find out how could I Create or
modify user in domain:
PrincipalContext pc = new
PrincipalContext(System.DirectoryServices.AccountManagement.ContextType.Domain, "your domain");
UserPrincipal up = UserPrincipal.FindByIdentity(pc,
IdentityType.Sid, WindowsIdentity.GetCurrent().User.Value);
That's regarding the currunt user; if you need to create a new user do this:
UserPrincipal newUser = new UserPrincipal(pc, "Some NEw Name", "password",
true /*Enabled or not*/);
newUser.Save();
> The following has been edited out of a bit of code I use but should work;
>
[quoted text clipped - 45 lines]
> > >
> > > Willy.