from
http://groups.google.com/groups?q=C%23+ADSI+directoryentry+setpassword&hl=en&lr=&ie=UTF8&oe=UTF8&selm=maZpmDJ5BHA.1624%40cpmsftngxa07&rnum=5
using System;
using System.DirectoryServices; namespace SampleCode
{
class CreateUserClass
{
[STAThread]
static void Main(string[] args)
{
CreateUser("LDAP://DOM/cn=users,dc=dom,dc=extest,dc=microsoft,dc=com",
"Logon","FirstName","Last","paword");
}
static bool CreateUser
(
string strContainerPath,//Parent Container
string strLogon, //Logon/SAMAccountName
string strFirstName, //User’s First Name
string strLastName, //User’s Last Name
string strPassword //Desired Password
)
{
DirectoryEntry oContainer, oNewUser;
try
{
//Bind to the parent container
oContainer = new
DirectoryEntry(strContainerPath);
oNewUser = oContainer.Children.Add("CN=" +
strFirstName + " " + strLastName, "user");
//SAMAccountName is required!
oNewUser.Properties["sAMAccountName"].Add(strLogon);
oNewUser.Properties["sn"].Add(strLastName);
oNewUser.Properties["givenName"].Add(strFirstName);
//This will enable the account:
oNewUser.Properties["userAccountControl"].Add(544);
//Save the Changes
oNewUser.CommitChanges();
//Set Password
oNewUser.Invoke("SetPassword", new string
[]{strPassword});
return true;
}
catch(System.Exception exception)
{
//Report the error
System.Diagnostics.Debug.WriteLine("CreateUser(" + strLogon + ") FAILED: "
+ exception.Message);
return false;
}
}
}
}
http://groups.google.com/groups?q=C%23+ADSI+directoryentry+setpassword&hl=en&lr=&ie=UTF8&oe=UTF8&selm=maZpmDJ5BHA.1624%40cpmsftngxa07&rnum=5
using System;
using System.DirectoryServices; namespace SampleCode
{
class CreateUserClass
{
[STAThread]
static void Main(string[] args)
{
CreateUser("LDAP://DOM/cn=users,dc=dom,dc=extest,dc=microsoft,dc=com",
"Logon","FirstName","Last","paword");
}
static bool CreateUser
(
string strContainerPath,//Parent Container
string strLogon, //Logon/SAMAccountName
string strFirstName, //User’s First Name
string strLastName, //User’s Last Name
string strPassword //Desired Password
)
{
DirectoryEntry oContainer, oNewUser;
try
{
//Bind to the parent container
oContainer = new
DirectoryEntry(strContainerPath);
oNewUser = oContainer.Children.Add("CN=" +
strFirstName + " " + strLastName, "user");
//SAMAccountName is required!
oNewUser.Properties["sAMAccountName"].Add(strLogon);
oNewUser.Properties["sn"].Add(strLastName);
oNewUser.Properties["givenName"].Add(strFirstName);
//This will enable the account:
oNewUser.Properties["userAccountControl"].Add(544);
//Save the Changes
oNewUser.CommitChanges();
//Set Password
oNewUser.Invoke("SetPassword", new string
[]{strPassword});
return true;
}
catch(System.Exception exception)
{
//Report the error
System.Diagnostics.Debug.WriteLine("CreateUser(" + strLogon + ") FAILED: "
+ exception.Message);
return false;
}
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货