[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Directory Service C# Lot of Points

Posted on 2004-10-28
14
Medium Priority
?
274 Views
Last Modified: 2008-01-09
I have this code which hopefully should create a new user on the gtdemo domain which is the domain i am logged on to.

However when it runs there are no errors but it does not create a new user, Can anyone help me figure this out.

Also is there a way to set up an exchange mailbox when creating a new user.

DirectoryEntry obDirEntry = null;

obDirEntry = new DirectoryEntry("WinNT://gtdemo");
DirectoryEntries entries = obDirEntry.Children;
DirectoryEntry obUser = entries.Add("Test", "User");
obUser.Properties["FullName"].Add("Test");
object obRet = obUser.Invoke("SetPassword", "Test");
obUser.CommitChanges();

Thanks

0
Comment
Question by:WVW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12432694
are you adding them to a group?

'Get object in ADs
Dim usr As DirectoryEntry = GetADsObject("person", loginUser, sUserProps, False)
Dim grp As DirectoryEntry = GetADsObject("group", groupName, sLoadProps, True)
If Not grp Is Nothing And Not usr Is Nothing Then
  'set authentication info for using ADs, feel free to create
  'a function for authenticating to AD.
  usr.AuthenticationType = AuthenticationTypes.Delegation
  usr.Username = "username"
  usr.Password = "password"
  grp.AuthenticationType = AuthenticationTypes.Delegation
  grp.Username = "username"
  grp.Password = "password"
  If Not IsMember(usr, grp) Then
    Dim strDisName As String = usr.Properties("distinguishedName").Value
    grp.Properties("Member").Add(strDisName)
    grp.CommitChanges()
  End If
End If

sorry for the vb:

http://www.wwwcoder.com/main/parentid/272/site/2150/68/default.aspx

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12432706
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12432712
Heres a prebuilt class for Acitive Directory Manipulation:
http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:WVW
ID: 12432923
What is a group and why do i need one to add users, i dont have any groups when i go to exchange users i click on the treeview for users and it displays them without a group
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12432934
are you just trying to add a user to exchange server?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12432949
public void AddDirectoryObject(string AdsiParentPath,string ObjectName,
string ObjectSchemaName,object[,] Properties,object[,] MethodsToInvoke)
{
// connect to the selected directory parent object
DirectoryEntry DirEntry = new DirectoryEntry(AdsiParentPath);

try
{
// creates the new directory object
DirectoryEntry NewObject = DirEntry.Children.Add(ObjectName,ObjectSchemaName);

// now loop through all the properties and set them
if (Properties != null)
{
for (int Count = 0; Count < Properties.GetLength(0); Count++)
NewObject.Properties[Convert.ToString(Properties[Count,0])].
Value = Properties[Count,1];
}

// now loop through all the methods and invoke them
if (MethodsToInvoke != null)
{
for (int Count = 0; Count < MethodsToInvoke.GetLength(0); Count++)
NewObject.Invoke(Convert.ToString(MethodsToInvoke[Count,0]),
MethodsToInvoke[Count,1]);
}

// commit the changes
NewObject.CommitChanges();
NewObject.Close();
}

// catch any exception accessing the directory object
catch (Exception e)
{ }

// close the directory object
finally
{
DirEntry.Close();
}
}
http://www.c-sharpcorner.com/Code/2004/Aug/DirectoryServices.asp
0
 

Author Comment

by:WVW
ID: 12433004
I need to be able to add them to the active directory and assign a username and password so they can login and also i need to assign them an exchange mailbox as well.

The domain i need to logon to is gtdemo.

If anyone can give some insight into what code i need to use and how it works they can have the points.

Regards
0
 

Author Comment

by:WVW
ID: 12434910
I have put a tracer in and found why my code does not work, it says

"General access denied error\r\n"

This the code again, do i need to give it login credential to get to active directory

string strDoamin = "gtdemo";
                        string strLogin = "test";
                        string strPwd = "test";
                        DirectoryEntry obDirEntry = null;
                        try
                        {
                              obDirEntry = new DirectoryEntry("WinNT://" + strDoamin);
                              DirectoryEntries entries = obDirEntry.Children;
                              DirectoryEntry obUser = entries.Add(strLogin, "User");
                              obUser.Properties["FullName"].Add("Amigo");
                              object obRet = obUser.Invoke("SetPassword", strPwd);
                              obUser.CommitChanges();
                        }
                        catch (Exception ex)
                        {
                              Trace.Warn(ex.Message);
                        }
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12435006
private static string ADPath=ConfigurationSettings.AppSettings["ADFullPath"].ToString() ;
private static string ADUser = ConfigurationSettings.AppSettings["ADAdminUser"].ToString() ;
private static string ADPassword = ConfigurationSettings.AppSettings["ADAdminPassword"].ToString() ;

http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp
0
 

Author Comment

by:WVW
ID: 12442575
Hi, i have got some code working which is as follows, however i could not get the code to insert the new user in the Users section of active directory instead it inserts in straight into the root node on active directory.

First person to modify my code to work so the user is inserted into the Users section get the points

Also a few question on line 3 it says user is that the acount type, and where can i find a list of mydirectoryEntry properties

Thanks

1. obDirEntry = new DirectoryEntry("LDAP://gtdemo","administrator","test");
2. DirectoryEntries myEntries = obDirEntry.Children;
3. DirectoryEntry myDirectoryEntry = myEntries.Add("CN=Test", "user");
4. myDirectoryEntry.Properties["name"].Value="Test";
5. myDirectoryEntry.Properties["samAccountName"].Value="Test";
6. myDirectoryEntry.CommitChanges();
0
 

Author Comment

by:WVW
ID: 12443438
I have solved the problem by using this code. Who feels they deserve the points, if you can justify why you can have them if not i will request a refund.

Thanks

obDirEntry = new DirectoryEntry ("LDAP://CN=Users,DC=gtdemo,DC=local" ,"administrator","test");
                              //obDirEntry = new DirectoryEntry("LDAP://gtdemo","administrator","test");
                  
                              DirectoryEntries myEntries = obDirEntry.Children;
                              
                              // Name of Logon
                              DirectoryEntry myDirectoryEntry = myEntries.Add("CN=JDixon", "user");
                              
                              //First Name
                              myDirectoryEntry.Properties["givenName"].Value="Jonathan";
                              //Surname
                              myDirectoryEntry.Properties["sn"].Value="Dixon";
                              // Logon Name
                              myDirectoryEntry.Properties["userPrincipalName"].Value="JDixon";
                              myDirectoryEntry.Properties["samAccountName"].Value="JDixon";
                              myDirectoryEntry.CommitChanges();
0
 
LVL 17

Accepted Solution

by:
AerosSaga earned 1960 total points
ID: 12443484
If you feel I helped you come to this conclusion with my inofrmation then award the points.  If you feel I did not aid in your coming to this conlcusion, then ask for a refund.

Aeros
0
 

Author Comment

by:WVW
ID: 12443942
I like your honesty and i will be honest with you, it did not help much but you can have the points anyway.

Thanks for helping
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12444019
np, thanks for the points
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

656 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