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
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)

 

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

 

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?

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
Link to post
Share on other sites
  • Colduction changed the title to Array to Combo-box [SOLVED]

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 EmilyLove
      I have a string containing the full path of an executable and an array of executables without their paths. I am trying to compare the string to the list in the array and if a match is found, remove it from the array. The entry get removed from the array successfully, and after checking its return result, uses it to update the ubound if it succeeded, but it doesn't want to update to the new value. Any ideas what I am doing wrong? It acts like it is read-only.
      #include <Array.au3> #include <File.au3> Local $sApp_Exe = "F:\App\Nextcloud\nextcloud.exe" Local $aWaitForEXEX = [3, "Nextcloud.exe", "nextcloudcmd.exe", "QtWebEngineProcess.exe"] For $h = 1 To $aWaitForEXEX[0] If StringInStr($sApp_Exe, $aWaitForEXEX[$h]) <> 0 Then $iRet = _ArrayDelete($aWaitForEXEX, $h) If $iRet <> -1 Then $aWaitForEXEX[0] = $iRet ;this line doesn't work. $aWaitForEXEX[0] doesn't update and shortly gives Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.: _ArrayDisplay($aWaitForEXEX) EndIf Next  
    • By vinnyMS
      #Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0]) $w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns  
       
      i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel
      you will have to create a "copy" button if possible
      array.au3 2.txt
    • By DannyJ
      I have a dataset like this, (a strubg)
      Username: User1 Type: Admin RegDate: 1999 Username: User2 Type: User RegDate: 2000 How to make a 2 dimensional array that I can display with _ArrayDisplay?
      This would be a perfect 2D array to represent my data:
      Username           Tpye RegDate User1              Admin 1999 User2              User 2000   If you run this Powershell this powershell command, you can get this dataset that I am talking about:
      Get-LocalUser | Select * With this code you can try it to read into a string:
      #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include "GUIListViewEx.au3" #include <Array.au3> ; Just for display in example #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=y #EndRegion $sCommand = "powershell.exe Get-LocalUser | Select *" Local $iPid = Run($sCommand, @WorkingDir , @SW_SHOW , $STDOUT_CHILD) ProcessWaitClose($iPid) Local $sOutput = StdoutRead($iPID) ConsoleWrite($sOutput) How can I correctly split $sOutput into a 2D array (with the above mentioned layout) that I can display and I work with?
    • By ute_man
      Hi Forum,
      I am struggling to select an IP address from "Server Interface" dropdown (ComboBox2) of tftpd32 client.
      tftpd32 is a TFTP server - TFTPD32 : an opensource IPv6 ready TFTP server/service for windows : TFTP server (pagesperso-orange.fr)
      The IP addresses (and the associated interfaces) are dynamic in ComboBox2.
      What I want to do is to select an item from ComboBox2 which contains a given IP address (eg. 192.168.2.1) - (which is hidden in the picture as it is at the bottom of the list) and fill the edit field with the selection. (Note : the ComboBox items contain the IP address and the Interface name, therefore IP address is just a part of the item)
      I am not sure whether functions such as _GUICtrlComboBox_SelectString() are only to be used with Autoit generated ComboBoxes.
      Please help !!!!
      My code below, it does not select the ComboBox2 item with my IP address 192.168.2.1.
      Local $hWnd=ControlGetHandle("Tftpd32 by Ph. Jounin", "", 4008) Sleep(100) ControlFocus("Tftpd32 by Ph. Jounin", "", $hWnd) Sleep(100) Local $IP = "192.168.2.1" _GUICtrlComboBox_SelectString($HWnd, $IP) ComboBox2 ID = 4008


    • By kovlad
      My solution is to write nested arrays without copying.
      The problem was described hier.
       
      Function:
      #include <Array.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ArrayNestedSet ; Description ...: Assigns a value to an element of a nested 1D array. ; Syntax ........: _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue) ; Parameters ....: $aArray - an array of arrays. ; $vIndex - an index or 1d-array of indexes; ; a size if $vValue not defined (zero to delete). ; $vValue - a value (create, resize or delete if not defined). ; ; Return values .: on success - 1 ; @extended - nesting level of operation ; on failure - 0 ; @extended - nesting level of error ; @error = 1 - invalid array ; @error = 2 - invalid index ; Author ........: ; Modified ......: kovlad ; Remarks .......: ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/185638-assign-a-value-to-an-array-in-array-element/ ; https://www.autoitscript.com/trac/autoit/ticket/3515?replyto=description ; Example .......: Yes ; =============================================================================================================================== Func _ArrayNestedSet(ByRef $aArray, $vIndex, $vValue = Default) Local $extended = @extended + 1 If IsArray($vIndex) Then If UBound($vIndex, 0) <> 1 Then _ Return SetError(2, $extended) If UBound($vIndex) > 1 Then If UBound($aArray, 0) <> 1 Then _ Return SetError(1, $extended) ; keep index for this array Local $i = $vIndex[0] If $i < 0 Or UBound($aArray) <= $i Then _ Return SetError(2, $extended) ; delete index of this array _ArrayDelete($vIndex, 0) ; recursive function call Local $return = _ArrayNestedSet($aArray[$i], $vIndex, $vValue) If @error Then Return SetError(@error, @extended + 1, 0) Else Return SetExtended(@extended + 1, 1) EndIf Else $vIndex = $vIndex[0] EndIf EndIf If $vValue = Default Then If $vIndex < 0 Then _ Return SetError(2, $extended) If $vIndex = 0 Then ; delete array and free memory $aArray = 0 Return SetExtended($extended, 1) EndIf If UBound($aArray, 0) = 1 Then ; resize array keeping data ReDim $aArray[$vIndex] Return SetExtended($extended, 1) Else ; create new nested array Local $aTmp[$vIndex] $aArray = $aTmp Return SetExtended($extended, 1) EndIf Else If UBound($aArray) <= $vIndex Then _ Return SetError(2, $extended + 1) ; set value of array entry $aArray[$vIndex] = $vValue Return SetExtended($extended, 1) EndIf EndFunc  
      Examples:
      ; write value to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 1st nested array" & @CRLF) Local $aTmp1[4] = [1,2,3,4] _ArrayDisplay($aTmp1, "$aTmp1") Local $aArray[2] = [$aTmp1] ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 3, 14) = " & _ArrayNestedSet($aArray[0], 3, 14) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; resize 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 1st nested array" & @CRLF) ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 8) = " & _ArrayNestedSet($aArray[0], 8) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay($aArray[0], "$aArray[0]") ; write array to 1st nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write array to 1st nested array" & @CRLF) Local $aTmp11[4] = [11,12,13,14] _ArrayDisplay($aTmp11, "$aTmp11") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], 2, $aTmp11) = " & _ArrayNestedSet($aArray[0], 2, $aTmp11) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; write value to 2nd nested array using index array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write value to 2nd nested array using index array" & @CRLF) Local $aIndex1[2] = [2,3] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1, 140) = " & _ArrayNestedSet($aArray[0], $aIndex1, 140) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; resize 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : resize 2nd nested array" & @CRLF) Local $aIndex1[2] = [2,8] _ArrayDisplay($aIndex1, "$aIndex1") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex1) = " & _ArrayNestedSet($aArray[0], $aIndex1) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay(($aArray[0])[2], "($aArray[0])[2]") ; create new 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : create new 3rd nested array" & @CRLF) Local $aIndex2[3] = [2,7,6] _ArrayDisplay($aIndex2, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex2) = " & _ArrayNestedSet($aArray[0], $aIndex2) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF & @CRLF) _ArrayDisplay((($aArray[0])[2])[7], ")($aArray[0])[2])[7]") ; delete 3rd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 3rd nested array" & @CRLF) Local $aIndex3[3] = [2,7,0] _ArrayDisplay($aIndex3, "$aIndex2") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex3) = " & _ArrayNestedSet($aArray[0], $aIndex3) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray((($aArray[0])[2])[7]) = " & IsArray((($aArray[0])[2])[7]) & @CRLF & @CRLF) ; write 0 in 1st nested array to delete the 2nd nested array ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : write 0 in 1st nested array to delete the 2nd nested array" & @CRLF) Local $aIndex4[1] = [2] _ArrayDisplay($aIndex4, "$aIndex4") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex4, 0) = " & _ArrayNestedSet($aArray[0], $aIndex4, 0) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray(($aArray[0])[2]) = " & IsArray(($aArray[0])[2]) & @CRLF & @CRLF) ; delete 1st nested array (same as '$aArray[0] = 0') ConsoleWrite("@@ Debug(" & @ScriptLineNumber & ") : delete 1st nested array (same as '$aArray[0] = 0')" & @CRLF) Local $aIndex5[1] = [0] _ArrayDisplay($aIndex5, "$aIndex5") ConsoleWrite( _ "_ArrayNestedSet($aArray[0], $aIndex5) = " & _ArrayNestedSet($aArray[0], $aIndex5) & @CRLF & _ " @error = " & @error & @CRLF & _ " @extended = " & @extended & @CRLF) ConsoleWrite("IsArray($aArray[0]) = " & IsArray($aArray[0]) & @CRLF & @CRLF)  
×
×
  • Create New...