7 Replies - 2252 Views - Last Post: 04 September 2012 - 01:33 PM Rate Topic: -----

#1 barocho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-September 12

Windows Form to Create Active Directory User

Posted 04 September 2012 - 11:50 AM

Okay, so I am stuck and I hope someone could help me out. I know how to create an user for Active Directory on Powershell and VB by reading a csv file. but i would like to create a form the displays text boxes and I could enter the information so it could be created in Active Directory.

I am having issue in connecting the text boxes to the source code, so it could do it's thing. for example i create a text box called "empname" and i want to call it in the source code to get the information entered and by it to ["samAccountName"]properties.

I hope this makes any sense.

thank you for you help.

Is This A Good Question/Topic? 0
  • +

Replies To: Windows Form to Create Active Directory User

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5625
  • View blog
  • Posts: 12,061
  • Joined: 02-June 10

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 11:59 AM

Pretty much the same as VB - you have all the same properties - for example the .Text property


string EmployeeName = empname.Text;

or

empname.Text = "Yogi Bear";
Was This Post Helpful? 0
  • +
  • -

#3 barocho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-September 12

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 12:02 PM

what's a good book for beginners on C#? thanks for the quick reply
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5625
  • View blog
  • Posts: 12,061
  • Joined: 02-June 10

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 12:04 PM

Here's my standard 'Beginners Resources' post...


First learn the language by working 2-5 "Learn C# in 30 days" type books cover to cover. Do a couple hundred on-line tutorial projects where you build what you're told to build, the way you are told to build it WITH AN EXPLANATION OF WHY so you can learn.

Then later you can start architecting your own simple stuff. Build a calculator. Build a DVD library program. Etc. Stuff that doesn't involve the complexity of a game. Then move up to games.



There are three routes people seem to take when learning programming.
  • Just start trying to create programs
  • Start taking apart other programs and try to figure out the language by reverse engineering
  • Follow a guided learning course (school or self-teaching books)


For the life of me I can't figure out why people try 1 & 2. I strongly suggest taking the guided learning approach. Those book authors go in a certain order for a reason: They know what they're doing and they know the best order to learn the materials.

Quote

Where do I start?


You start by learning a coding language FIRST.
Learn to plan before you type.
THEN you start designing software with a purpose.


If this sounds like you

Newbie/Rookie said:

I have a little programming experience but I need to write ...
read this section
Spoiler


Otherwise, you can just jump to the resources here:
Some of the tutorials below are for C# or Java not C, C++, VB.NET [...]. But the conceptual stuff of classes, object oriented design, events etc. are not language specific and should give you enough guidance in theory of program development for you to be able to look-up specific code example in your chosen coding language.



Resources, references and suggestions for new programmers. - Updated Mar 2012
Spoiler

Was This Post Helpful? 0
  • +
  • -

#5 barocho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-September 12

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 12:44 PM

this is what i have so far, but i think something is wrong, not sure of what it is

        private void button1_Click(object sender, EventArgs e)
        {
            string EmployeeName = empName.Text;
            string EmployeePassword = password.Text;

            string oGUID = string.Empty;
            string connectionPrefix = "LDAP://Server2008";

            DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);

            DirectoryEntry newUser = dirEntry.Children.Add("CN=" + EmployeeName, "user");

            newUser.Properties["samAccountName"].Value = EmployeeName;
            newUser.CommitChanges();

            oGUID = newUser.Guid.ToString();

            newUser.Invoke("SetPassword", new object[] { EmployeePassword });
            newUser.CommitChanges();
            
            dirEntry.Close();
            newUser.Close();




okay this is what i have but i am having issues with the LDAP connection?


            string EmployeeName = empName.Text;
            string EmployeePassword = password.Text;

            string oGUID = string.Empty;
            string connectionPrefix = "LDAP://207.141.205.11";

            DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);

            DirectoryEntry newUser = dirEntry.Children.Add("CN=" + EmployeeName, "user");

            newUser.Properties["samAccountName"].Value = EmployeeName;
            newUser.CommitChanges();

            oGUID = newUser.Guid.ToString();

            newUser.Invoke("SetPassword", new object[] { EmployeePassword });
            newUser.CommitChanges();
            
            dirEntry.Close();
            newUser.Close();


Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3647
  • View blog
  • Posts: 11,415
  • Joined: 05-May 12

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 12:53 PM

What error are you getting and and which line?
Was This Post Helpful? 0
  • +
  • -

#7 barocho  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 04-September 12

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 12:56 PM

line 7 and 9 are highlighted and it says "COMException was unhandled" check the error code property of the exception to determine the HRESULT returned by the COM object

System.Runtime.InteropServices.COMException was unhandled
Message=The server is not operational.

Source=System.DirectoryServices
ErrorCode=-2147016646
StackTrace:
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_IsContainer()
at System.DirectoryServices.DirectoryEntries.CheckIsContainer()
at System.DirectoryServices.DirectoryEntries.Add(String name, String schemaClassName)
at new_employee.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\barocho\Desktop\TechData\new_employee\new_employee\new_employee\Form1.cs:line 40
at System.Windows.Forms.Control.onclick(EventArgs e)
at System.Windows.Forms.Button.onclick(EventArgs e)
at System.Windows.Forms.Button.onmouseup(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
at System.Windows.Forms.Nativewindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at new_employee.Program.Main() in C:\Users\barocho\Desktop\TechData\new_employee\new_employee\new_employee\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3647
  • View blog
  • Posts: 11,415
  • Joined: 05-May 12

Re: Windows Form to Create Active Directory User

Posted 04 September 2012 - 01:33 PM

I don't know if this will help, but it's someplace to start: http://msdn.microsof...(v=VS.100).aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1