home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / ADSDK.ZIP / Samples / WinNT / Group / vb / Group.bas next >
Encoding:
BASIC Source File  |  1999-03-16  |  4.2 KB  |  143 lines

  1. Attribute VB_Name = "Group"
  2. Sub Main()
  3.  
  4. '----------------------------------------------------------------------------
  5. '
  6. '  Microsoft Active Directory 2.5 Sample Code
  7. '
  8. '  Copyright (C) Microsoft Corporation, 1996 - 1999
  9. '
  10. '  File:       group.bas
  11. '
  12. '  Contents:   Creating Group in a domain or local computer
  13. '
  14. '----------------------------------------------------------------------------
  15.  
  16. Dim grp As IADsGroup
  17. Const ADS_GROUP_TYPE_LOCAL_GROUP = 4
  18.  
  19. '-----------------------------------------
  20. '--- CREATING A LOCAL GROUP IN  A DOMAIN
  21. '-----------------------------------------
  22. Set dom = GetObject("WinNT://INDEPENDENCE")
  23. Set grp = dom.Create("group", "DSys")
  24. grp.Put "groupType", ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP
  25. grp.Description = "Distributed System Group"
  26. grp.SetInfo
  27.  
  28. '-----------------------------------------
  29. '--- CREATING A GLOBAL GROUP IN  A DOMAIN
  30. '-----------------------------------------
  31. Set dom = GetObject("WinNT://INDEPENDENCE")
  32. Set grp = dom.Create("group", "PM")
  33. grp.Put "groupType", ADS_GROUP_TYPE_GLOBAL_GROUP
  34. grp.Description = "Program Managers"
  35. grp.SetInfo
  36.  
  37.  
  38. '-----------------------------------------
  39. '--- CREATING A LOCAL GROUP IN  A COMPUTER
  40. '-----------------------------------------
  41. Set comp = GetObject("WinNT://SEATTLE,computer")
  42. Set grp = comp.Create("group", "TheSmiths")
  43. grp.Put "groupType", ADS_GROUP_TYPE_LOCAL_GROUP
  44. grp.Description = "The Smiths Family Member"
  45. grp.SetInfo
  46.  
  47.  
  48.  
  49. '----------------------------------------------------
  50. '--- ADDING A USER IN A DOMAIN LOCAL or GLOBAL GROUP
  51. '----------------------------------------------------
  52. Set grp = GetObject("WinNT://INDEPENDENCE/DSys,group")
  53. grp.Add ("WinNT://INDEPENDENCE/JSmith")
  54.  
  55.  
  56.  
  57. '-------------------------------------------------
  58. '--- ADDING A USER IN A LOCAL GROUP IN A COMPUTER
  59. '--------------------------------------------------
  60. Set comp = GetObject("WinNT://SEATTLE,computer")
  61. Set grp = comp.GetObject("group", "TheSmiths")
  62. grp.Add ("WinNT://INDEPENDENCE/JSmith")
  63.  
  64.  
  65.  
  66. '----------------------------------------------------
  67. '--- ADDING A GLOBAL GROUP TO LOCAL GROUP IN A DOMAIN
  68. '----------------------------------------------------
  69. Set grp = GetObject("WinNT://INDEPENDENCE/DSys,group")
  70. grp.Add ("WinNT://INDEPENDENCE/PM,group")
  71.  
  72.  
  73. '--------------------------------------------------
  74. ' ENUMERATING GROUPS IN A DOMAIN
  75. '-------------------------------------------------
  76. Set dom = GetObject("WinNT://INDEPENDENCE")
  77. dom.Filter = Array("Group")
  78.  
  79. '--- Local Group
  80. Debug.Print "Local Groups---"
  81. For Each grp In dom
  82.   If (grp.GroupType = ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP) Then
  83.     Debug.Print grp.Name
  84.   End If
  85. Next
  86.  
  87. '-- Global Group
  88. Debug.Print "Global Groups---"
  89. For Each grp In dom
  90.   If (grp.GroupType = ADS_GROUP_TYPE_GLOBAL_GROUP) Then
  91.      Debug.Print grp.Name
  92.   End If
  93. Next
  94.  
  95. '--------------------------------------------------
  96. ' ENUMERATING GROUPS IN A COMPUTER
  97. '-------------------------------------------------
  98. Set comp = GetObject("WinNT://SEATTLE,computer")
  99. comp.Filter = Array("Group")
  100.  
  101. 'All groups in a computer is a local group
  102. Debug.Print "Groups:"
  103. For Each grp In comp
  104.   Debug.Print grp.Name
  105. Next
  106.  
  107.  
  108. '--------------------------------------------------
  109. ' ENUMERATING GROUPS MEMBERSHIP
  110. '-------------------------------------------------
  111. Set grp = GetObject("WinNT://INDEPENDENCE/DSys,group")
  112. For Each member In grp.Members
  113.   Debug.Print member.Name & "   (" & member.Class & ")"
  114.   
  115.   'A local group may contain a global group
  116.   'We can enumerate the global group membership as well
  117.   If (member.Class = "Group") Then
  118.       For Each obj In member.Members
  119.          Debug.Print "    " & obj.Name & "   (" & obj.Class & ")"
  120.       Next
  121.   End If
  122. Next
  123.  
  124. '-----------------------------------------------------
  125. ' REMOVING MEMBER FROM A GROUP
  126. '-----------------------------------------------------
  127. Set grp = GetObject("WinNT://INDEPENDENCE/PM,group")
  128. grp.Remove ("WinNT://INDEPENDENCE/ChristyH")
  129.  
  130. '---------------------------------------------------
  131. ' IS MEMBER
  132. '---------------------------------------------------
  133. Set grp = GetObject("WinNT://INDEPENDENCE/DSys,group")
  134. If (grp.IsMember("WinNT://INDEPENDENCE/JSmith")) Then
  135.    Debug.Print "Yes"
  136. Else
  137.    Debug.Print "No"
  138. End If
  139.  
  140.  
  141.  
  142. End Sub
  143.