Jump to content

help with split string DOMAIN\USERNAME


 Share

Recommended Posts

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
Edited by nivtop
Link to comment
Share on other sites

nevermind.. i figured it out..

glad noone wasted time on this... i shouldve just spent a few more minutes before posting. sorry again

$Temp = StringReplace(StringTrimLeft($Output[2], StringInStr($Output[2], '=', 0, -1)), '"', '')
                    $aSystemUsers = StringReplace(StringTrimLeft($Output[1], StringInStr($Output[1], '=', 0, -1)), '"', '')

msgbox(0, "test", $Temp&"\"&$aSystemUsers, 0)
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...