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

  • Similar Content

    • By Zaoka
      Hi guys
      Need little help with filtering.
      I'm trying to filter specific weeks from power pivot table using this code recorded with Excel VBA :
       
      #include <Excel.au3> Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookOpen($oExcel, "C:\Users\....\Orders.xlsb") $oWorkbook.PivotTables("PivotTable1").PivotFields( _ "[Report 2].[Week].[Week]").VisibleItemsList = Array( _ "[Report 2].[Week].&[10]", "[Report 2].[Week].&[11]", _ "[Report 2].[Week].&[12]", "[Report 2].[Week].&[13]", _ "[Report 2].[Week].&[14]", "[Report 2].[Week].&[15]") But get error
      error: Array(): undefined function. Not sure how to resolve this.
    • By LxP
      I'm trying to pass a nested array to a function, such that the function alters the inner array.
      I was surprised to find that this minimal reproducible example, despite its use of ByRef, seems to pass a copy of the inner array to the function:
      #include <Array.au3> ; a boring old array Local $aInnerArray[5] = [1, 2, 3, 4, 5] ; a one-element array containing a reference to the other array Local $aOuterArray[1] = [$aInnerArray] ; intention: take a nested array and alter its inner array ; reality: the inner array seems to be getting copied Func ChangeIt(ByRef $aOuter) Local $aInner = $aOuter[0] $aInner[2] = 0 EndFunc ; Expected: [1, 2, 3, 4, 5] ; Actual: [1, 2, 3, 4, 5] ✔ _ArrayDisplay($aInnerArray, 'Before') ; $aOuterArray passed by-ref, should receive reference to $aInnerArray ; Therefore should change $aInnerArray to [1, 2, 0, 4, 5] ChangeIt($aOuterArray) ; Expected: [1, 2, 0, 4, 5] ; Actual: [1, 2, 3, 4, 5] ✘ _ArrayDisplay($aInnerArray, 'After') I suspect that either:
      the copy is taking place in the first line of the function (I couldn't find a way to access the inner array without first assigning it to a variable though); or ByRef doesn't propagate into inner levels of the data structure being passed, which seems less likely to me. Could someone please point me in the right direction to get this working as intended?
      Update: the answer
      ; WRONG: ; a one-element array containing a reference to the other array Local $aOuterArray[1] = [$aInnerArray] The assumption I made about this code is wrong—it actually copies $aInnerArray into $aOuterArray, so there are now two unrelated $aInnerArray instances.  It is not possible to store arrays in other arrays by reference.
      If it is necessary to refer to a mutable array in multiple places, consider holding it in a global variable.  Where a collection of mutable arrays needs to be accessed in multiple places (as in my case), consider storing them in a global array and referring to each sub-array by index (also known as the Registry pattern).
    • By VinMe
      HELLO All,
      is there any function in Auto it to Remove the repeating  strings separated by ","  which is present in the array.
      ex.
      Available state
      a[0]= D97,D96,,D85,D86,D85,D86,D85,D86,D85,,D86,D85,D86,D85,D86
      a[1]=D85,D24,,,,,D85
      Required state
      a[0]= D97,D96,D85,D86,
      a[1]=D85,D24
      thank  you in advance!
      vin!
    • By D2thunder
      Hi all, I wasnt active in this Forum forum for Years. 😅
      Since I need something with Json in AutoIt i write a little UDF to save a variable to file to read it with another language - and back. After a while until my other script grows i thought - lets integrate all variables wich is possible, because i want have arrays to.
      This is my first public UDF in Autoit - normaly my AutoIt scripts are quick an dirty.... - like the examples for this udf. - someone want to write nice examples?
      I tried to write this UDF properly, cared for processing speed, low mem consumption as possible, a short code, and a high usability without beeing very familiar with arrays.
      What is it for? - convert nearly all types of variables to a json string for saving it in a file or to an ini. Read it back in to a same formated variable and preserv variable types. All array types are supported with nested arrays, the only restriction is ram and array/stringsize - and time if the array is very big. You can use Filters for variable types and some other options.
      If anyone found a bug or any suggestions, please post it.
       
      get Json.au3 from here Json.au3
       
       
      JsonVar 2019.01.25.1.zip
    • By sksbir
      Hi
      Trying this from autoit v3.3.14.5 and SCITE 3.19.102.1901.0 :
      help file , page "Language Reference - Variables" , sample autoit script about maps:

      Maps must be declared before use by defining their scope using the 'Global/Local/Static' keywords. Local $mControls[]
      So is my test script : only with this local declation.
      -check syntax is OK
      - running script : 

      test.au3" (13) : ==> Variable subscript badly formatted.: Local $mControls[] Local $mControls[^ ERROR ->14:51:49 AutoIt3.exe ended.rc:1
      any clue ?
×
×
  • Create New...