Jump to content

How to collect system user names?


Morteza
 Share

Recommended Posts

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...