General discussion


Global Group Information

By ask_anurag ·

I have Windows NT Domain and in that Domain i have some group so i need to take usernames from Group.

For Ex. I want to take out all the users name which are there in Domain Admins list.
Can someone tell me as soon as possible how i can do it.
I have tried ifmember but in it i have to give user name individually.

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by BFilmFan In reply to Global Group Information

You can use this script:

Option Explicit
Dim Domain, Server

'create a domain object
Set Domain = CreateObject("UserManager.Domain")

'Enumerate servers in the domain
For Each Server In Domain.Servers
ListGroupsOnServer Server

'this sub lists all groups on one server
Sub ListGroupsOnServer(Server)
Dim Group, Member

'Enumerate all local groups
For Each Group In Server.LocalGroups

'Print server and group name
Wscript.Echo server.Name, group.Name

For Each Member In Group.Members
If IsObject(Member) Then
Wscript.Echo " *", Member.Name
Wscript.Echo " *", Member
End If

End Sub

Collapse -

by BFilmFan In reply to

To do accounts by group

Dim Server, Group, Member

Set Server = CreateObject("UserManager.Server")
Server.Select ""
For Each Group In Server.Groups
Debug.Print Group.Name
For Each Member In Group.Members
If IsObject(Member) Then
Debug.Print Group.Name, ",", Member.Name
Debug.Print Group.Name, ",", Member
End If
Next Group

Collapse -

by BFilmFan In reply to

To enumerate local groups, use this:

'Windows type used to call the Net API
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&

lgrpi1_name As Long
End Type

Private Declare Function NetLocalGroupEnum Lib "netapi32" _
(servername As Byte, _
ByVal Level As Long, _
buff As Long, _
ByVal buffsize As Long, _
entriesread As Long, _
totalentries As Long, _
resumehandle As Long) As Long

Private Declare Function NetApiBufferFree Lib "netapi32" _
(ByVal lpBuffer As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pTo As Any, uFrom As Any, _
ByVal lSize As Long)

Private Declare Function lstrlenW Lib "kernel32" _
(ByVal lpString As Long) As Long

Private Sub Form_Load()

Command1.Caption = "Enum Local Groups"

With ListView1

.ColumnHeaders.Add , , "Group Name"
.View = lvwReport
.FullRowSelect = True

End With

End Sub

Private Sub Command1_Click()

Dim bServer() As Byte
Dim tmp As String

bServer = "\\workstation" & vbNullChar

'required to show server in caption
tmp = bServer

Label1.Caption = GetLocalGroups(bServer) & " local groups found on " & tmp

End Sub

Collapse -

by BFilmFan In reply to

Private Function GetLocalGroups(bServer() As Byte) As Long

Dim bufptr As Long
Dim entriesread As Long
Dim totalentries As Long
Dim success As Long
Dim resumehandle As Long
Dim nStructSize As Long
Dim cnt As Long
Dim itmx As ListItem

nStructSize = Len(lgis)

success = NetLocalGroupEnum(bServer(0), _
0, bufptr, _
entriesread, _
totalentries, _

If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then

For cnt = 0 To entriesread - 1

'get one chunk of data and cast
'into an LOCALGROUP_INFO_1 type, and
'add the group name to a list
CopyMemory lgis, ByVal bufptr + (nStructSize * cnt), nStructSize

'add the group name to the listview
Set itmx = ListView1.ListItems.Add(, , GetPointerToByteStringW(lgis.lgrpi1_name))


End If

Call NetApiBufferFree(bufptr)

GetLocalGroups = entriesread

End Function

Public Function GetPointerToByteStringW(ByVal dwData As Long) As String

Dim tmp() As Byte
Dim tmplen As Long

If dwData <> 0 Then

tmplen = lstrlenW(dwData) * 2

If tmplen <> 0 Then

ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp

End If

End If

End Function

Collapse -

by BFilmFan In reply to

That's VBscript.

I don't know of a method via a batch file, except to call the script.

Collapse -

by ask_anurag In reply to Global Group Information


Thanks for your reply but I am not able to execute WScript can you please tell me how I can do through batch file.



Related Discussions

Related Forums