Results 1 to 14 of 14

Thread: Create computer account in Active Directory using certain credentials.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Create computer account in Active Directory using certain credentials.

    Below is the code that works if I am logged into our windows network with an admin account.
    It does not work however, if I log into a normal users account. What would be the best way to accomplish this with a LDAP connection string? Ive tried many different way's but cannot for the life of me figure it out. Any help is appreciated.

    Thanks,



    Dim NewPCName As String = TextBox1.Text
    Dim CompContainer As New DirectoryEntry(TextBox3.Text)
    Dim NewPCPath As String = ("LDAP://cn=" & NewPCName & "," & TextBox2.Text)

    If DirectoryEntry.Exists(NewPCPath) Then
    'The account already exists so we alert the user
    MessageBox.Show("The specific Computer account already exists in " & CompContainer.ToString)
    Else
    'The account does not exist, so we create it
    Dim CompAccount As DirectoryEntry = CompContainer.Children.Add("cn=" & NewPCName, "Computer")
    CompAccount.Properties.Item("SAMAccountName").Value = NewPCName & "$"
    CompAccount.Properties.Item("UserAccountControl").Value = 4096
    CompAccount.Properties.Item("dNSHostName").Value = TextBox1.Text + ".joi.johnsonoutdoors.com"

    CompAccount.CommitChanges()
    CompAccount.Close()
    MessageBox.Show("Created the account successfully.")
    End If

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Create computer account in Active Directory using certain credentials.

    It does not work however, if I log into a normal users account.
    Apparently it's rude when I put "Well duh!" so I won't!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Create computer account in Active Directory using certain credentials.

    Right mouse click - Run as Administrator ?
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    It's a click once application, that's not really an option.

  5. #5
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    Re: Create computer account in Active Directory using certain credentials.

    If you can't locate that in the context menu, you can always use the "runas" command.

    Code:
    runas /user:domain\username app.exe
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Create computer account in Active Directory using certain credentials.

    Wouldn't Windows impersonation help in this case? I know it can be used on AD for asp.net apps but i am not sure if will do the trick here.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    Quote Originally Posted by mbutler755 View Post
    If you can't locate that in the context menu, you can always use the "runas" command.

    Code:
    runas /user:domain\username app.exe
    Yep, I knew that part. Still, it's a click once application. I don't want them to be messing with a .exe.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    I looked at impersonation, just not sure how to get it right. I tried to do it earlier today with no success. Crappy this is the only part I need to fix

  9. #9
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Create computer account in Active Directory using certain credentials.

    If what mbutler says works then you don't need them to mess with the .exe. You will execute the command internally through the process class.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    Quote Originally Posted by sapator View Post
    If what mbutler says works then you don't need them to mess with the .exe. You will execute the command internally through the process class.
    Ah... so something like...

    Process.Start("\\remotelocation\*.exe", "runas /user:domain\username")

    Either way, I may look into impersonation. Even then I would have to mess with the .exe, and updates will be a PITA, vs a Click Once.

  11. #11
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Create computer account in Active Directory using certain credentials.

    Something like that but the parameters go to a separate object.Anyhow you get the idea. Good night.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    Quote Originally Posted by sapator View Post
    Something like that but the parameters go to a separate object.Anyhow you get the idea. Good night.
    I would still like to be able to get it done without messing with the .exe.

    Anybody have any ideas?


    *Public Shared Function GetDirectoryEntry() As DirectoryEntry
    * * * * Dim de As DirectoryEntry = New DirectoryEntry()
    * * * * de.Path = computer.TextBox3.Text
    * * * * de.Username = "joi\" & login.TextBox1.Text
    * * * * de.Password = login.TextBox2.Text
    * * * * Return de
    * * End Function

    Ive tried using this but apparently, i'm not doing it right.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    77

    Re: Create computer account in Active Directory using certain credentials.

    Runas is not working properly. I will need to figure out how to make a LDAP connection string and do the commands once i'm connected.

  14. #14
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Create computer account in Active Directory using certain credentials.

    Oh good grief. You can't create a new account except from an admin account. It's Windows 101! That's all there is to it. You can continue chasing your tail trying to subvert this but it won't ever wash.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width