Results 1 to 4 of 4

Thread: getting group names from a domain with code ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    getting group names from a domain with code ?

    Hi
    I have a problem , I have been asked if it is possible to get all the groups iin a domain that the user logs on to.
    ie when the program I am writing runs it will pick up what domain I am logged onto and then retrieve all the groups in the domain by name to populate a list box.

    Is this even possible ?

    How would I go about this any idea's? as I dont even know where to start , this is a bit out of my league.

    Rgds ,Locutus
    Resistance is futile

  2. #2
    Hyperactive Member
    Join Date
    Nov 2003
    Location
    In Front of my computer...
    Posts
    367
    if it is from a website you can parse the info you need and add it then to the list box else dont know explain al ittle more
    Born to help others
    (If I've been helpful then please rate my post. Thanks)

    call me EJ or be slapped!

  3. #3
    Junior Member
    Join Date
    Mar 2003
    Posts
    30

    okay a little more info

    Hi
    A little more info on the problem I have.

    The user of the application will log on to the network at work and log into the uk domain of my organisation.
    I want then to be able to make a text file or list box then of all the groups in the domain that I am logged onto on the work network. This is nothing to do with web sites as mention above.

    Any one able to help ?

    Is this even possible ?

    The user will be using a regular win 95 machine which is not a server.

    Rgds, Knoxvile

  4. #4
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Newbury, UK
    Posts
    1,878
    Its not my work, and I haven't actually used it.
    I am not sure if it will give you what you want.
    However, the attached has some filenames that mak it sound as though they could be what you want...


    OR the following .VBS file might have some ideas in it....
    VB Code:
    1. '
    2. ' Checks for membership of a group
    3. '
    4. Function IsMember(sGroup)
    5.     Dim sAdsPath, oUser, oGroup
    6.     If IsEmpty(oGroupDict) Then
    7.         Set oGroupDict         = CreateObject("Scripting.Dictionary")
    8.         oGroupDict.CompareMode = vbTextCompare
    9.  
    10.         sAdsPath  = oNet.UserDomain & "/" & oNet.UserName
    11.         Set oUser = GetObject("WinNT://" & sAdsPath & ",user")
    12.         For Each oGroup In oUser.Groups
    13.             oGroupDict.Add oGroup.Name, "-"
    14.         Next
    15.         Set oUser = Nothing
    16.     End If
    17.  
    18.     IsMember = CBool(oGroupDict.Exists(sGroup))
    19. End Function
    20. '
    21. '================================================================================
    22. '
    23. Option Explicit ' Force explicit declarations
    24. '
    25. ' Variables
    26. '
    27. Dim WSHNetwork
    28. Dim FSO
    29. Dim strUserName ' Current user
    30. Dim strUserDomain ' Current User's domain name
    31. Dim ObjGroupDict ' Dictionary of groups to which the user belongs
    32. Dim strDrive ' Drive letter
    33. Dim strShare ' Share path (UNC)
    34. Dim colDrives ' Enumerate Drives
    35. Dim i ' Another variable
    36.  
    37. Set WSHNetwork = WScript.CreateObject("WScript.Network")
    38. Set FSO = CreateObject("Scripting.FileSystemObject")
    39. '
    40. ' Wait until the user is really logged in...
    41. '
    42. strUserName = ""
    43. While strUserName = ""
    44. WScript.Sleep 100 ' 1/10 th of a second
    45. strUserName = WSHNetwork.UserName
    46. Wend
    47. strUserDomain = WSHNetwork.UserDomain
    48.  
    49. ' Read the user's account "Member Of" tab info across the network
    50. ' once into a dictionary object.
    51.  
    52. Set ObjGroupDict = CreateMemberOfObject(strUserDomain, strUserName)
    53.  
    54. 'GROUP1
    55. If MemberOf(ObjGroupDict, "GROUP1") Then
    56.     'Map network Drives
    57.         Call ConnectNetworkDrives("W:", "\\SERVER\SHARE1")
    58.     'Connect Printer(s)
    59.         WSHNetwork.AddWindowsPrinterConnection "\\SERVER\PRINTER1"
    60.     'Set Default printer
    61.         'WSHNetwork.SetDefaultPrinter "\\SERVER\PRINTER1"
    62. End If
    63.  
    64.  
    65. 'GROUP2
    66. If MemberOf(ObjGroupDict, "GROUP2") Then
    67.     'Map Network Drives
    68.         'Call ConnectNetworkDrives("<LETTER>:", "\\<SERVER>\<SHARE>")
    69.     'Connect Printer(s)
    70.         WSHNetwork.AddWindowsPrinterConnection "\\SERVER\PRINTER2"
    71.     'Set Default printer
    72.         'WSHNetwork.SetDefaultPrinter "\\SERVER\PRINTER2"
    73. End If
    74.  
    75. Function MemberOf(ObjDict, strKey)
    76. ' Given a Dictionary object containing groups to which the user
    77. ' is a member of and a group name, then returns True if the group
    78. ' is in the Dictionary else return False.
    79. '
    80. ' Inputs:
    81. ' strDict - Input, Name of a Dictionary object
    82. ' strKey - Input, Value being searched for in
    83. ' the Dictionary object
    84. ' Sample Usage:
    85. '
    86. ' If MemberOf(ObjGroupDict, "DOMAIN ADMINS") Then
    87. ' wscript.echo "Is a member of Domain Admins."
    88. ' End If
    89. '
    90. '
    91. MemberOf = CBool(ObjGroupDict.Exists(strKey))
    92.  
    93. End Function
    94.  
    95.  
    96. Function CreateMemberOfObject(strDomain, strUserName)
    97. ' Given a domain name and username, returns a Dictionary
    98. ' object of groups to which the user is a member of.
    99. '
    100. ' Inputs:
    101. '
    102. ' strDomain - Input, NT Domain name
    103. ' strUserName - Input, NT username
    104. '
    105. Dim objUser, objGroup
    106.  
    107. Set CreateMemberOfObject = CreateObject("Scripting.Dictionary")
    108. CreateMemberOfObject.CompareMode = vbTextCompare
    109. Set objUser = GetObject("WinNT://" & strDomain & "/" & strUserName &
    110. ",user")
    111. For Each objGroup In objUser.Groups
    112. CreateMemberOfObject.Add objGroup.Name, "-"
    113. Next
    114. Set objUser = Nothing
    115.  
    116. End Function
    117.  
    118. Function ConnectNetworkDrives(strDrive, strShare)
    119. ' Input drive letter and share path
    120. ' This function connects a drive letter to a specified share share
    121.  
    122. ' Inputs:
    123.  
    124. ' strDrive = Drive letter e.g. "W:"
    125. ' strShare = Share path e.g. "\\Server\Share"
    126.  
    127.    Set colDrives = wshNetwork.EnumNetworkDrives
    128.    For i = 0 To colDrives.Count - 1 Step 2
    129.       If (colDrives(i) = strDrive) Then
    130.          wshNetwork.RemoveNetworkDrive strDrive
    131.       End If
    132.    Next
    133.    wshNetwork.MapNetworkDrive strDrive, strShare
    134. End Function
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width