Sign in to follow this  
Followers 0
Morteza

How to collect system user names?

4 posts in this topic

Dear friends,

On a multiuser system, how can I collect all of the system's user names under Administrator permission?

Regards

Share this post


Link to post
Share on other sites



Taken from ptrex and modified a bit to default to admin.

CODE
#include <array.au3>

; Initialize error handler

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$GroupPath = InputBox("List Group Members", "Enter DOMAIN/GROUP to list: ","Administrators")

$avUsers = _GroupGetMembers($GroupPath)

If Not @error Then

_ArrayDisplay($avUsers, "Users in group")

Else

MsgBox(16, "Error", "Error returned: @error = " & @error)

EndIf

; ------------------------------------------------------------

; Function _GroupGetMembers($sPath)

; Call with: _GroupGetMembers($sPath)

; Where: $sPath = DOMAIN/GROUP, i.e. "MyDomain/Domain Admins"

; If Domain is not included, uses local machine, i.e. "Administrators" will be xlated to "./Administrators"

; On success returns an array of members in the specified group with [0] = count.

; For an empty group, returns [0] = 0.

; On failure sets @error.

; ------------------------------------------------------------

Func _GroupGetMembers($sPath)

Local $oUser, $sRET = "", $avRET

; Check path to group

$sPath = StringReplace($sPath, "\", "/") ; Don't use backslash with WMI path

If Not StringInStr($sPath, "/") Then $sPath = "./" & $sPath ; Use local if no domain given

; Get group object

Local $oGroup = ObjGet("WinNT://" & $sPath)

If IsObj($oGroup) Then

For $oUser In $oGroup.Members

$sRET &= $oUser.Name & @LF

; $sRET &= $oUser.Name & "," & $oUser.mail & "," & $oUser.telephoneNumber & "," & $oUser.facsimileTelephoneNumber & @LF

Next

; Split into an array for return

$avRET = StringSplit(StringStripWS($sRET, 2), @LF)

; Change result for empty group [0] = 0

If $avRET[1] = "" Then Local $avRET[1] = [0]

Return $avRET

Else

; Error getting group object

Return SetError(1, 0, 0)

EndIf

EndFunc ;==>_GroupGetMembers

Func MyErrFunc()

$HexNumber=hex($oMyError.number,8)

Msgbox(0,"COM Error Test","We intercepted a COM Error !" & @CRLF & @CRLF & _

"err.description is: " & @TAB & $oMyError.description & @CRLF & _

"err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _

"err.number is: " & @TAB & $HexNumber & @CRLF & _

"err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _

"err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _

"err.source is: " & @TAB & $oMyError.source & @CRLF & _

"err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _

"err.helpcontext is: " & @TAB & $oMyError.helpcontext _

)

SetError(1) ; to check for after this function returns

Endfunc

Share this post


Link to post
Share on other sites

Thank you very much dbzfanatic,

Both for good answer and fast answer :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0