Tech Off Thread

2 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Please help find mistake.

Back to Forum: Tech Off
  • User profile image

    I write a programm witch nead add user  to active directory.... Programm write in C# console... when i build project dont have problem but when i test this programm in Windows 2003 server had problem
    like that.. You can see at this homepage image that i had
    Can you help me!
    And mybe can some other way define domain not like that
                DirectoryEntry adUserFolder = new DirectoryEntry("LDAP://CN=Users,DC=Sporta6,");
    Maybe can some other write when programm automatic detect domain!
    Sample programm i fide
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.DirectoryServices;
    namespace test
        class Program
            public struct UserInfo
                public string username;
                public string saMAccountName;
                public string firstName;
                public string initials;
                public string lastName;
                public string displayName;
                public string officeName;
                public string telephoneNumber;
                public string emailAddress;
            static void Main(string[] args)
                UserInfo newUserInfo;
                newUserInfo.firstName = "Agrita";
                newUserInfo.lastName = "XXX";
                newUserInfo.initials = "AX";
                newUserInfo.displayName = " Agrita XXX";
                newUserInfo.emailAddress = "";
                newUserInfo.officeName = "Sales";
                newUserInfo.telephoneNumber = "3716114426";
                newUserInfo.username = "AgritaX";
                newUserInfo.saMAccountName = "AgritaX";
                DirectoryEntry adUserFolder = new DirectoryEntry("LDAP://CN=Users,DC=Sporta6,");
                if (adUserFolder.SchemaEntry.Name == "container")
                    DirectoryEntry newUser = adUserFolder.Children.Add("CN=" + newUserInfo.username, "User");
                    if (DirectoryEntry.Exists(newUser.Path))
                        Console.WriteLine("The user:" + newUser.Username + "exists they will be deleted");
                        adUserFolder.Children.Remove(new DirectoryEntry(newUser.Path));
                    newUser.Properties["sAMAccountName"].Value = newUserInfo.saMAccountName;
                    newUser.Properties["givenName"].Value = newUserInfo.firstName;
                    newUser.Properties["sn"].Value = newUserInfo.lastName;
                    newUser.Properties["initials"].Value = newUserInfo.initials;
                    newUser.Properties["displayName"].Value = newUserInfo.displayName;
                    newUser.Properties["physicalDeliveryOfficeName"].Value = newUserInfo.officeName;
                    newUser.Properties["telephoneNumber"].Value = newUserInfo.telephoneNumber;
                    newUser.Properties["mail"].Value = newUserInfo.emailAddress;
                    newUser.Invoke("setpassword", "P@ssword1");
                    newUser.Properties["userAccountControl"].Value = 0x0200;
                    Console.WriteLine("User: " + newUserInfo.username + " successful created");
                    Console.WriteLine("Hit any key to continue....");

  • User profile image

    This was already answered in the coffee house for you.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.