ADSI and Visual Basic .NET 2005  
Author Message
glassman324





PostPosted: Visual Basic Language, ADSI and Visual Basic .NET 2005 Top

I have been trying for most of the day now to transform the following 
vbscript into visual basic .net 2005 with no luck whatsoever.  The script 
adds an existing security group in active directory into a remote computer's 
Administrators group.

vbscript
Set oAdminGroup = GetObject("WinNT://ServerName/Administrators,group")
oAdminGroup.Add "WinNT://Domain/SecurityGroup,group"
Call oAdminGroup.SetInfo

visual basic .net 2005
Dim oAdminGroup As New DirectoryEntry("WinNT://ServerName/Administrators")
oAdminGroup.Children.Add(SecurityGroup, "group")
oAdminGroup.CommitChanges()

The following Error is what I receive:
System.InvalidOperationException: The Active Directory object located at the 
path WinNT://ServerName/Administrators is not a container.

Any thoughts would be great.  Thanks.


Visual Basic12  
 
 
glassman324





PostPosted: Visual Basic Language, ADSI and Visual Basic .NET 2005 Top

This is what it needs to be:

visual basic .net 2005
Dim oAdminGroup As New DirectoryEntry("WinNT://ServerName/Administrators")
oAdminGroup.Invoke("Add", New Object() {"WinNT://DomainName/GroupName"})
oAdminGroup.CommitChanges()

Thank you Joe Kaplan!