Hi,
I have to create a new user in active directory2000 and 2003. In AD 2003 I am 
not able to set Domain property (Please find attached screen shot) through 
code. Is there any way to set domain property? The same piece of code is 
working for AD 2000.

 

Any help for the above problem would be much appreciated. 

Any suggestion/ideas are welcome.

 

if(bFlag)

{

      strServerName = " Server2003";

      strAdminName = "snetadmin ";

      strAdminPassword = "abc";

      strDomainName = "a.com";

      strRefPath = "LDAP://Server2003/CN=Mani Jain,OU=a,OU=Domain 
Controllers,DC=a,DC=com";

}

else

{

      strServerName = "Server2000";

      strAdminName = "ServiceNetAdmin";

      strAdminPassword = "sample";

      strDomainName = "b.com";

      strRefPath = "LDAP://Server2000/CN=Mani,OU=b,OU=Domain 
Controllers,DC=b,DC=com";

}

 

int iStart = strRefPath.IndexOf("CN=");

int iEnd = strRefPath.IndexOf(",", iStart);

string strValOU = "";

if (iStart  > 0)

{

      strValOU = strRefPath.Substring(0, iStart);

}

if (iEnd > 0)

{

      strValOU = strValOU  +  strRefPath.Substring(iEnd + 1);

}

strServerPath = strValOU;

                  

DirectoryEntry objDirectoryEntry = new DirectoryEntry(strServerPath, 
strAdminName, strAdminPassword, AuthenticationTypes.Secure);

                  

//Add the User

DirectoryEntries objDirectryEntries = objDirectoryEntry.Children;

DirectoryEntry objNewDirectoryEntry = objDirectryEntries.Add("CN=" + 
txtUserName.Text.Trim(), "user");

 

objNewDirectoryEntry.Properties["userPrincipalName"].Value = 
txtUserName.Text.Trim();

objNewDirectoryEntry.Properties["samAccountName"].Value = 
txtUserName.Text.Trim();

objNewDirectoryEntry.Properties["sn"].Value = "2";

objNewDirectoryEntry.Properties["givenName"].Value = "A";

objNewDirectoryEntry.Properties["UserPassword"].Value = "abc";

 

objNewDirectoryEntry.CommitChanges();

strServerPath = "LDAP://" + strServerName;

if(bFlag)

strServerPath = this.GetUserPath(txtUserName.Text.Trim() + "@" + strDomainName, 
strServerPath, strAdminName, strAdminPassword, bFlag);

else

      strServerPath = this.GetUserPath(txtUserName.Text.Trim(), strServerPath, 
strAdminName, strAdminPassword,bFlag);

 

DirectoryEntry objDirectoryEntry1 = new DirectoryEntry(strServerPath, 
strAdminName, strAdminPassword, AuthenticationTypes.Secure);

int iUAC = 
Convert.ToInt32(objDirectoryEntry1.Properties["userAccountControl"].Value);

iUAC = iUAC & ~(C_ADS_UF_ACCOUNTDISABLE); //Activate the account

objDirectoryEntry1.Properties["userAccountControl"].Value =iUAC; //Reset the 
property.

objDirectoryEntry1.CommitChanges();

 

Regards,
krishnan


[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get fast access to your favorite Yahoo! Groups. Make Yahoo! your home page
http://us.click.yahoo.com/dpRU5A/wUILAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to