-
Jan 2nd, 2014, 05:47 PM
#1
Thread Starter
Lively Member
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
-
Jan 2nd, 2014, 05:58 PM
#2
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!
-
Jan 2nd, 2014, 07:09 PM
#3
Re: Create computer account in Active Directory using certain credentials.
Right mouse click - Run as Administrator ?
-
Jan 2nd, 2014, 09:32 PM
#4
Thread Starter
Lively Member
Re: Create computer account in Active Directory using certain credentials.
It's a click once application, that's not really an option.
-
Jan 2nd, 2014, 09:41 PM
#5
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
-
Jan 2nd, 2014, 09:57 PM
#6
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 2nd, 2014, 10:05 PM
#7
Thread Starter
Lively Member
Re: Create computer account in Active Directory using certain credentials.
Originally Posted by mbutler755
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.
-
Jan 2nd, 2014, 10:06 PM
#8
Thread Starter
Lively Member
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
-
Jan 2nd, 2014, 10:51 PM
#9
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 2nd, 2014, 11:16 PM
#10
Thread Starter
Lively Member
Re: Create computer account in Active Directory using certain credentials.
Originally Posted by sapator
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.
-
Jan 3rd, 2014, 12:10 AM
#11
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jan 3rd, 2014, 09:07 AM
#12
Thread Starter
Lively Member
Re: Create computer account in Active Directory using certain credentials.
Originally Posted by sapator
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.
-
Jan 3rd, 2014, 01:13 PM
#13
Thread Starter
Lively Member
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.
-
Jan 3rd, 2014, 04:00 PM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|