Link to home
Start Free TrialLog in
Avatar of stevendijkman
stevendijkmanFlag for Netherlands

asked on

VBScript: How do I assign a group to another group in Win2K?

L.S.,

I'm working on an automated procedure to implement a security model on a server, like doing user to group assignments, user creation, file system rights, things like that.

There's one thing I can't get done: assigning groups to other groups. I keep getting error 'A new member could not be added to a local group because the member has the wrong account type.'

Here's the code I use:

Sub doAddGroupsToGroup(strDomain, strParentGroup, strNestedGroup)
      Dim objDomain
      Dim objParentGroup
      Dim objNestedGroup
      Set objDomain = GetObject("WinNT://" & strDomain)
      Set objParentGroup = GetObject("WinNT://" & strDomain & "/" & strParentGroup & ",group")
      Set objNestedGroup = GetObject("WinNT://" & strDomain & "/" & strNestedGroup & ",group")
            
      doLog 4, "Adding group '" & objNestedGroup.Name & "' to group '" & objParentGroup.Name & "'..."
      objParentGroup.Add(objNestedGroup.AdsPath)
      
      ' most-common error trapping            
      If (Hex(Err.Number) = 80070562) Then ' user already resides in that group
            doLog 4, "Group '" & objNestedGroup.Name & "' already resides in group '" & objParentGroup.Name & "'."
      Else
            doLog 0, "Group '" & objNestedGroup.Name & "' was added to group '" & objParentGroup.Name & "' successfully."
      End If
              
      Set objGroup = Nothing
      Set objDomain = Nothing
End Sub

Notes:
- the doLog subroutine is a routine that basically does nothing but echo to the console log and log the same thing to a log file.
- I know the error handling is NOT what it should be right now, I'll get to that later...

Thanks for any help! Regards,
Steven Dijkman.
ASKER CERTIFIED SOLUTION
Avatar of mpantana
mpantana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, to confirm the above from mpantana, you should just try this using the MMC snapin (or usrmgr on NT). I don't think it's possible to nest global groups like this so I don't recko the manual method will work either.

Cheers
Julian