Hello, i'm very sorry for being such a noob at splitting strings but I can't figure this out. I'm trying to get the result of: DOMAINUSERNAME From this code I found it split the string to only "USERNAME" and i cant figure out how to get the "DOMAIN" part back into it. I realized this won't give me the true domain name.. just computername if I split it. Does anyone know how to get a full list of DOMAIN/Useraccounts ? LOCALusername1 LOCALusername2 DOMAINusername3 DOMAINusername4 etc.... #include <Array.au3>
$Users = _SystemUsers(0)
_ArrayDisplay($Users)
#cs ===============================================================================
Function: _SystemUsers($AccountType = 0)
Description: Return an array with the local or domain username
Parameter(s): $AccountType: Local, domain or both username
0 = Local and Domain usernames
1 = Local usernames only
2 = Domain usernames only
Returns: An array with the list of usernames - Succeeded
@error 1 - Didn't query any username
@error 2 - Failed to create Win32_SystemUsers object
@error 3 - Invalid $AccountType
Author(s): Danny35d
#ce ===============================================================================
Func _SystemUsers($AccountType = 0)
Local $aSystemUsers
Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20
Local $colItems = "", $strComputer = "localhost"
If Not StringRegExp($AccountType, '[012]') Then Return SetError(3, 3, '')
$objWMIService = ObjGet("winmgmts:" & $strComputer & "rootCIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_SystemUsers", "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objItem In $colItems
$Output = StringSplit($objItem.PartComponent, ',')
If IsArray($Output) Then
$Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '')
If $AccountType = 0 Or ($AccountType = 1 And @ComputerName = $Temp) Then
$aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|'
ElseIf $AccountType = 2 And @ComputerName <> $Temp Then
$aSystemUsers &= StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '') & '|'
EndIf
EndIf
;$aSystemUsers &= $Output[1]
Next
$aSystemUsers = StringTrimRight($aSystemUsers, 1)
If $aSystemUsers = '' Then Return(SetError(1, 1, $aSystemUsers))
Return(SetError(0, 0, StringSplit($aSystemUsers, '|')))
Else
$aSystemUsers = ''
Return(SetError(2, 2, $aSystemUsers))
EndIf
EndFunc ;==>_SystemUsers