public class DSUser { public DSUser(System.DirectoryServices.DirectoryEntry user) { this.domainName=user.Path; this.Username=user.Name; this.Password=user.Password; try { this.FullName=Convert.ToString(user.Invoke("Get", new object[] {"FullName"})); this.Description=Convert.ToString(user.Invoke("Get", new object[] {"Description"})); this.PasswordExpired=Convert.ToInt32(user.Invoke("Get", new object[] {"PasswordExpired"})); this.RasPermissions=Convert.ToInt32(user.Invoke("Get", new object[] {"RasPermissions"})); this.MaxStorage=Convert.ToInt32(user.Invoke("Get", new object[] {"MaxStorage"})); this.PasswordAge=Convert.ToInt32(user.Invoke("Get", new object[] {"PasswordAge"})); this.HomeDirectory=Convert.ToString(user.Invoke("Get", new object[] {"HomeDirectory"})); this.LoginScript=Convert.ToString(user.Invoke("Get", new object[] {"LoginScript"})); this.HomeDirDrive=Convert.ToString(user.Invoke("Get", new object[] {"HomeDirDrive"})); this.userDirEntry=user; }catch(Exception e) { throw(new Exception("Could not load user from given DirectoryEntry")); } } public DSUser(string Username, string Password, string DomainName) { domainName=DomainName; if(domainName=="" || domainName==null) domainName=Environment.MachineName; username=Username; password=Password; }
public static DirectoryEntry GetDirectoryEntry(){ DirectoryEntry de = new DirectoryEntry(); de.Path = "LDAP://192.168.1.1/CN=Users;DC=Yourdomain"; de.AuthenticationType = AuthenticationTypes.Secure; return de; } /// <summary> /// Method used to create an entry to the AD. /// Replace the path, username, and password. /// </summary> /// <returns>DirectoryEntry</returns> public static DirectoryEntry GetDirectoryEntry(){ DirectoryEntry de = new DirectoryEntry(); de.Path = "LDAP://192.168.1.1/CN=Users;DC=Yourdomain"; de.Username = @"yourdomain\sampleuser"; de.Password = "samplepassword"; return de; } 這樣就行了....
public DSUser(System.DirectoryServices.DirectoryEntry user) {
this.domainName=user.Path;
this.Username=user.Name;
this.Password=user.Password;
try {
this.FullName=Convert.ToString(user.Invoke("Get", new object[]
{"FullName"}));
this.Description=Convert.ToString(user.Invoke("Get", new
object[] {"Description"}));
this.PasswordExpired=Convert.ToInt32(user.Invoke("Get", new
object[] {"PasswordExpired"}));
this.RasPermissions=Convert.ToInt32(user.Invoke("Get", new
object[] {"RasPermissions"}));
this.MaxStorage=Convert.ToInt32(user.Invoke("Get", new object[]
{"MaxStorage"}));
this.PasswordAge=Convert.ToInt32(user.Invoke("Get", new object[]
{"PasswordAge"}));
this.HomeDirectory=Convert.ToString(user.Invoke("Get", new
object[] {"HomeDirectory"}));
this.LoginScript=Convert.ToString(user.Invoke("Get", new
object[] {"LoginScript"}));
this.HomeDirDrive=Convert.ToString(user.Invoke("Get", new
object[] {"HomeDirDrive"}));
this.userDirEntry=user;
}catch(Exception e) {
throw(new Exception("Could not load user from given
DirectoryEntry"));
}
}
public DSUser(string Username, string Password, string DomainName) {
domainName=DomainName;
if(domainName=="" || domainName==null)
domainName=Environment.MachineName;
username=Username;
password=Password;
}
public static DirectoryEntry GetDirectoryEntry(){
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://192.168.1.1/CN=Users;DC=Yourdomain";
de.AuthenticationType = AuthenticationTypes.Secure;
return de;
}
/// <summary>
/// Method used to create an entry to the AD.
/// Replace the path, username, and password.
/// </summary>
/// <returns>DirectoryEntry</returns>
public static DirectoryEntry GetDirectoryEntry(){
DirectoryEntry de = new DirectoryEntry();
de.Path = "LDAP://192.168.1.1/CN=Users;DC=Yourdomain";
de.Username = @"yourdomain\sampleuser";
de.Password = "samplepassword";
return de;
}
這樣就行了....