EDN Admin
Well-known member
I am writing a chunk of code to add a domain group to a local group on servers. The servers are part of the domain. The purpose is to simplify giving permissions to some of our application support teams.
I have written the following code to accomplish this. Everything works until I get to the real meat of the code, the highlighted section, which throws an "Unknown error (0x80005004)". txtUser is a text box with the name of the group to add.
Servers is a collection of strings with the server names, one per entry. txtPassword is just a text box for entering the password to use when connecting.
I have checked the server name, it is right, I have checked the admin ID Im using, it works, I have checked that the group does not already exist in the local administrators group, everything seems like it should work.
Dim RootDE As New DirectoryEntry("LDAP://MYDOMAIN.ORG")<br/>
Dim Filter As String = "(&(objectclass=group)(cn=" & txtUser.Text.Trim & "))"<br/>
Dim DS As New DirectorySearcher(RootDE, Filter)<br/>
Dim DSR As SearchResult = DS.FindOne<br/>
Dim GroupDE As New DirectoryEntry(DSR.Path)<br/>
<br/>
For Each Server As String In Servers<br/>
Dim SAMPath As String = "WinNT://MYDOMAIN.ORG/" & Server.Trim & "/Administrators"<br/>
Dim Password As String = txtPassword.Text<br/>
Dim LocalSAM As New DirectoryEntry(SAMPath, "MYDOMAINMyAdminUser", Password, AuthenticationTypes.Secure)
NOTE: Up to this point, everything works, the objects are created and populated correctly.
LocalSAM.Invoke("Add", GroupDE.Path) <br/>
LocalSAM.Close()<br/>
<br/>
Next
I am using VS 2010, .Net 4.0.
Anybody have any ideas? Is there another way I should go about doing this? Any samples would be helpful.
<
William Farrell VB.Net 2010
<br/>
<br/>
View the full article
I have written the following code to accomplish this. Everything works until I get to the real meat of the code, the highlighted section, which throws an "Unknown error (0x80005004)". txtUser is a text box with the name of the group to add.
Servers is a collection of strings with the server names, one per entry. txtPassword is just a text box for entering the password to use when connecting.
I have checked the server name, it is right, I have checked the admin ID Im using, it works, I have checked that the group does not already exist in the local administrators group, everything seems like it should work.
Dim RootDE As New DirectoryEntry("LDAP://MYDOMAIN.ORG")<br/>
Dim Filter As String = "(&(objectclass=group)(cn=" & txtUser.Text.Trim & "))"<br/>
Dim DS As New DirectorySearcher(RootDE, Filter)<br/>
Dim DSR As SearchResult = DS.FindOne<br/>
Dim GroupDE As New DirectoryEntry(DSR.Path)<br/>
<br/>
For Each Server As String In Servers<br/>
Dim SAMPath As String = "WinNT://MYDOMAIN.ORG/" & Server.Trim & "/Administrators"<br/>
Dim Password As String = txtPassword.Text<br/>
Dim LocalSAM As New DirectoryEntry(SAMPath, "MYDOMAINMyAdminUser", Password, AuthenticationTypes.Secure)
NOTE: Up to this point, everything works, the objects are created and populated correctly.
LocalSAM.Invoke("Add", GroupDE.Path) <br/>
LocalSAM.Close()<br/>
<br/>
Next
I am using VS 2010, .Net 4.0.
Anybody have any ideas? Is there another way I should go about doing this? Any samples would be helpful.
<
William Farrell VB.Net 2010
<br/>
<br/>
View the full article