Jump to content

Recommended Posts

Hi, i have a source code of "Danny35d" and i have 2 main question that are:

  1.  How to extract this function's results (Datas are as Array) to combo-box without set number of datas?
  2.  When i type 1, 2 in _SystemUsers($AccountType = 0) to get only Local or Domain users, it just give me both of them, it's old problem of this function, please share us debugged code :)❤
#include <Array.au3>

$Users = _ArrayToString(_SystemUsers(), "|", 1)
ConsoleWrite($Users & @CRLF)

#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 & "\root\CIMV2")
   $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
      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

Thanks to your best Team.

Edited by InfernalScorpion

Share this post


Link to post
Share on other sites

For #1 it is very easy.  Just create a GUI with a combo-box and use GUICtrlSetData ($idCombo, $Users) to store the values into the combo

For #2, can you run this, see if you get all users this way  (show the result if you can) :

#include <Constants.au3>

Global $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
Local $Output = "Computer: " & @ComputerName  & @CRLF
$Output &= "==========================================" & @CRLF

Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount")
If not IsObj($colItems) then Exit Msgbox(0,"WMI Output","No WMI Objects Found")
For $objItem In $colItems
  $Output &= "Caption: " & $objItem.Caption & @CRLF
Next
MsgBox ($MB_SYSTEMMODAL,"",$Output)

 

Share this post


Link to post
Share on other sites

Unfortunately in a domain environment Win32_UserAccount (takes forever to resolve domain users) if your disconnected from the network it works fine or if you only require local users you can use that within the query.

Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_UserAccount Where LocalAccount = True")

Couple of days ago I needed to query a couple of hundred user accounts that had profiles on multiple RDS servers and used the following method to get the user accounts:

#include <Array.au3>
#include <Security.au3>

Global $g_aProfileList[0]

_UserProfiles(4)

_ArrayDisplay($g_aProfileList)

;~ $_vDomain    : 0 - All Users on the system
;~              : 1 = NT Authority Users on the system
;~              : 2 = Local Users on the system
;~              : 3 = NT Authority + Local Users on the system
;~              : 4 = Domain Users on the system
;~              : 5 = NT Authority + Domain Users on the system
;~              : 6 = Local + Domain Users on the system
Func _UserProfiles($_vDomain = 0)
    Local $sRegProfileList = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    Local $aAccountSid, $sRegProfileGuid, $i = 1
    While 1
        $sRegProfileGuid = RegEnumKey($sRegProfileList, $i)
            If @error Then ExitLoop
        $aAccountSid = _Security__LookupAccountSid($sRegProfileGuid)
            If @error Then ContinueLoop
        If IsArray($aAccountSid) Then
            While 1
                Switch $_vDomain
                    Case 1
                        If ($aAccountSid[1] <> "NT Authority") Then ExitLoop
                    Case 2
                        If ($aAccountSid[1] <> @ComputerName) Then ExitLoop
                    Case 3
                        If Not ($aAccountSid[1] = "NT Authority" Or $aAccountSid[1] = @ComputerName) Then ExitLoop
                    Case 4
                        If ($aAccountSid[1] = "NT Authority" Or $aAccountSid[1] = @ComputerName) Then ExitLoop
                    Case 5
                        If $aAccountSid[1] = @ComputerName Then ExitLoop
                    Case 6
                        If $aAccountSid[1] = "NT Authority" Then ExitLoop
                EndSwitch
                ReDim $g_aProfileList[UBound($g_aProfileList) + 1]
                $g_aProfileList[UBound($g_aProfileList) - 1] = $aAccountSid[0]
                ExitLoop
            WEnd
        EndIf
        $i += 1
    WEnd
EndFunc

 

Share this post


Link to post
Share on other sites

Thanks @Nine, your code was tidy & summarized, but i have a little question of your First Souloution that you told:
 

17 hours ago, Nine said:

Just create a GUI with a combo-box and use GUICtrlSetData ($idCombo, $Users) to store the values into the combo

but requires Loop such as For or Do, my question is here, how to use these Loops to set all datas in combo-box?

Share this post


Link to post
Share on other sites

Hi @Subz, thanks for your care and your answer, i've tested your code on my machine and i didn't get all users, your code's problem is when a user was disabled such as Administrator or Guest, it doesn't show, but thanks for your reply :)❤

Edited by InfernalScorpion

Share this post


Link to post
Share on other sites

As Nine pointed out, you've already converted the array to string "_ArraytoString", so you just use "GuiCtrlSetData" to add that string to the combo box, there is no need for a loop

Share this post


Link to post
Share on other sites

Whoaaa, i didn't think that Combo-box supports array data from _ArrayToString() and it does't require loop for set all datas in it😀
I should test it first, then ask it :)

Thanks @Nine and @Subz, both of you helped me!

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jangal
      Hello friends
      This app is slow
      How to increase its speed?
       
      #include <Array.au3> #include <StringConstants.au3> #include <File.au3> #include <String.au3> Global $aWord[][2]  = [[1, "google"],[2,"hello"]]


        Global $sFileName = @ScriptDir & "\1.txt" ; 2MB Text File Local $sFileRead = FileRead($sFileName) Local $res = StringRegExp($sFileRead, "(*UCP)\b[\pL\d]{2,}", 3) _ArrayDisplay($res)   for $sWord in $res     $iIndex = _ArraySearch($aWord, $sWord, 0, 0, 0, 0, 1, 2)     ;MsgBox(0,0,$iIndex)     if $iIndex == -1 Then         Local $aFill = [[0,$sWord]]         _ArrayAdd($aWord,$aFill)        ;      Else         $aWord[$iIndex][0] +=1     EndIf   Next _ArrayDisplay($aWord)

      1.txt
    • By Colduction
      Hi dear friends!, i'm sorry for creating a new thread (a new problem), i have over than 9 lists that i want to combine them to be this (in this example, there are 3 test files):


      I've written a little code for splitting main information, but i really confused how to make results as "Output.txt", here is that code:
       
      $sRegex_1 = StringRegExp(FileRead("1.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_2 = StringRegExp(FileRead("2.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) $sRegex_3 = StringRegExp(FileRead("3.txt"), '(?s:(?<=\=\=\r\n)(.*?)(?=\r\n\=\=))', 3) For $i = 0 To UBound($sRegex_1) - 1 ConsoleWrite($sRegex_1[$i] & @CRLF) For $j = 0 To UBound($sRegex_2) - 1 ConsoleWrite($sRegex_2[$j] & @CRLF) For $k = 0 To UBound($sRegex_3) - 1 ConsoleWrite($sRegex_3[$k] & @CRLF) Next Next Next  
    • By nacerbaaziz
      hello evrybody
      here is an example about how to split your texts using a delimiter with the ability to select how much of delimiters shows in each colum  with $i_number
      e.g
      you have a long text and you want to split it in an array
      that evry colum have a number (n) of lines
      i made a function that do that for you
      just call it with a three params
      $s_text
      your text
      $i_number
      the number that you want to put in each col
      $s_siparator
      the siparator
      default is "|"
      here is the function with example
      i hope that it will be useful for you
       
      ****
       
      #include <Array.au3> $s_txt = "some text1some text2|some text3|some text4|some text5|some text6" $array = splitText($s_txt, 2) _ArrayDisplay($array) Func splitText($s_text, $i_number, $s_siparator = "|") Local $a_TXT = StringSplit($s_text, $s_siparator) Local $a_Return[$a_TXT[0] + 1] If ($a_TXT[0] <= $i_number) Or ($i_number <= 0) Then ReDim $a_Return[2] $a_Return[0] = 1 $a_Return[1] = $s_text Return $a_Return EndIf Local $i_Processed = 1, $i_arrayProcessed = 1 Do For $i = $i_Processed To ($i_Processed + $i_number) - 1 If ($a_TXT[0] < $i) Then ExitLoop If Not ($a_Return[$i_arrayProcessed]) Then $a_Return[$i_arrayProcessed] = $a_TXT[$i] Else $a_Return[$i_arrayProcessed] &= $s_siparator & $a_TXT[$i] EndIf $i_Processed += 1 Next $i_arrayProcessed += 1 Until ($a_TXT[0] < $i_Processed) ReDim $a_Return[$i_arrayProcessed] $a_Return[0] = $i_arrayProcessed - 1 Return $a_Return EndFunc ;==>splitText
      accept my greetings
      thanks to
      @Dan_555
      for his notes
       
    • By MesterPerfect
      good morning
      this is the first post here in the autoit forums
      i hope that you can help me in my problem
      i have a JSON encoded
      it a map of my forums
      where i want to make a treeview that have the same type of map
      e.g
      a system (as category)
      windows (as sub category)
      software (as an child item in the windows category)
      .....
      i don't know how to do that
      so, i know that i can do that using the json functions
      but i need your help about how we can do it as the type that i told you
      by the way i need to put the sub info for each item in an array that give me the ability to manage my items
      e.g
      can post thread
      can reply
      message cound ...
      you just give me a small example and i can continue.
      am sorry if this against the rules of the forum.
      but i realy searched a lot but i couldn't
      i hope some one give me the way.
      thank you very much in advance
       
      here is the link of json forum
      https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/
      and here is my encoded json file
       
      { "tree_map": { "0": [ 1, 5, 6, 7 ], "1": [ 2 ], "2": [ 4 ], "5": [ 3 ], "6": [ 8 ], "8": [ 9, 10 ] }, "nodes": [ { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 1, "node_id": 1, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Main category", "type_data": {} }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 2, "node_name": null, "node_type_id": "Forum", "parent_node_id": 1, "title": "Main forum", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 1, "title": "Main category", "node_type_id": "Category" }, { "node_id": 2, "title": "Main forum", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 1, "node_id": 4, "node_name": null, "node_type_id": "Forum", "parent_node_id": 2, "title": "my forums1", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 2, "node_id": 5, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "Perfect", "type_data": {} }, { "breadcrumbs": [ { "node_id": 5, "title": "Perfect", "node_type_id": "Category" } ], "description": "", "display_in_list": true, "display_order": 2, "node_id": 3, "node_name": null, "node_type_id": "Forum", "parent_node_id": 5, "title": "ahmed", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 3, "node_id": 6, "node_name": null, "node_type_id": "Forum", "parent_node_id": 0, "title": "autoit", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 8, "node_name": null, "node_type_id": "Forum", "parent_node_id": 6, "title": "examples", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 3, "node_id": 9, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "GUI", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [ { "node_id": 6, "title": "autoit", "node_type_id": "Forum" }, { "node_id": 8, "title": "examples", "node_type_id": "Forum" } ], "description": "", "display_in_list": true, "display_order": 31, "node_id": 10, "node_name": null, "node_type_id": "Forum", "parent_node_id": 8, "title": "windowEX", "type_data": { "allow_poll": true, "allow_posting": true, "can_create_thread": true, "can_upload_attachment": true, "discussion_count": 0, "last_post_date": 0, "last_post_id": 0, "last_post_username": "", "last_thread_id": 0, "last_thread_prefix_id": 0, "last_thread_title": "", "message_count": 0, "min_tags": 0, "require_prefix": false } }, { "breadcrumbs": [], "description": "", "display_in_list": true, "display_order": 4, "node_id": 7, "node_name": null, "node_type_id": "Category", "parent_node_id": 0, "title": "vbs", "type_data": {} } ] }  
    • By nooneclose
      I need to dynamically resize my 2d array while looping. 
      I know this code:
      ReDim $rArray[UBound($rArray) + 1] works for the rows, however, I also need to increase the columns. How would i go about increasing both rows and columns while looping? 
×
×
  • Create New...