kneze

read local Groups of remote Computer add to Combobox

9 posts in this topic

#1 ·  Posted (edited)

Hi

i try to read existing local Groups of remote computer and add to Combobox so i can select a Group to

get members and add to $ListMembers. Does anyone have a solution how i can read existing local Groups of remote computer and add to Combobox?

 

thanks.

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$Form1 = GUICreate("Add / Remove Members", 615, 432, 196, 128)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("", 8, 8, 289, 185)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelCpname = GUICtrlCreateLabel("CP Name:", 16, 32, 81, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputCpname = GUICtrlCreateInput("", 16, 56, 129, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$LabelLocalGroups = GUICtrlCreateLabel("Local Groups", 16, 96, 107, 20)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$ComboGroups = GUICtrlCreateCombo("", 16, 152, 273, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
GUICtrlSetBkColor(-1, 0xFFFF00)
$ButtonReadGroups = GUICtrlCreateButton("read local Groups", 160, 56, 130, 25)
$ButtonReadmembers = GUICtrlCreateButton("read Members", 16, 120, 130, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("User", 8, 200, 289, 89)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelUserID = GUICtrlCreateLabel("User ID:", 16, 224, 66, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputComputer = GUICtrlCreateInput("", 88, 216, 89, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$ButtonAdd = GUICtrlCreateButton("Add User", 184, 216, 100, 25)
$ButtonRemove = GUICtrlCreateButton("Remove user", 184, 248, 100, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListMembers = GUICtrlCreateList("", 304, 16, 305, 409)
GUISetState(@SW_SHOW)


While 1
    $msg = GUIGetMsg()
    Select
        ;Case $GUI_EVENT_CLOSE
             Case $msg = $GUI_EVENT_CLOSE
            Exitloop

         Case $msg = $ButtonReadGroups
            MsgBox(0, "Note", "Button 'read Groups' not work !")


         Case $msg = $ButtonReadmembers
            ;MsgBox(0, "Note", "Button 'Read Members' not work !")

          GUICtrlSetData($ListMembers, "")

       Local $readCombo = GuiCtrlRead($ComboGroups)

          GUICtrlSetData($ListMembers, $readCombo)


         Case $msg = $ButtonAdd
            MsgBox(0, "Note", "Button 'Add User' not working !")


         Case $msg = $ButtonRemove
            MsgBox(0, "Note", "Button 'Remove User' not working !")


    EndSelect
 WEnd

 func terminate()                                                                     ;exit
    Exit 0
EndFunc

 

Edited by kneze

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

These two functions return an array. So it's easy to populate the combo :

#Include <Array.au3>

$aUsers = _LocalAccounts_GetUserList("remotecomputername")
_ArrayDisplay($aUsers)
$aGroups = _LocalAccounts_GetGroupList("remotecomputername")
_ArrayDisplay($aGroups)


Func _LocalAccounts_GetUserList($sComputername = @ComputerName)
    Local $aFilter= ["user"], $aResult[1], $oUser

    Local $oComputer = ObjGet("WinNT://" & $sComputerName)
    If NOT IsObj($oComputer) Then Return SetError(1, 0, 0)

    $oComputer.Filter = $aFilter
    For $oUser In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oUser.Name
    Next
    $aResult[0] = UBound($aresult) - 1

    Return $aResult
EndFunc

Func _LocalAccounts_GetGroupList($sComputerName = @ComputerName)
    Local $aFilter = ["group"], $aResult[1], $oGroup

    Local $oComputer = ObjGet("WinNT://" & $sComputerName)
    If NOT IsObj($oComputer) Then Return SetError(1, 0, 0)

    $oComputer.Filter = $aFilter
    For $oGroup In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oGroup.Name
    Next
    $aResult[0] = UBound($aresult) - 1

    Return $aResult
EndFunc

 

Edited by jguinch

Share this post


Link to post
Share on other sites

closing double quotes is missing

$aUsers = _LocalAccounts_GetUserList("remotecomputername")

 

@kneze

Please read this:  How to post code on the forum

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

thanks jguinch and mLipok . I 'll try to use code in my GUI. Sorry for wrong way posting my code.

 

 

Share this post


Link to post
Share on other sites

Sorry for wrong way posting my code.

You can still edit your post, to fix it.


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hi now read local Groups on remote computer and put it to combobox works fine. Now i would like to red members of selected group, but array remains empty.

Please show me whats wrong.

 

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#Include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$Form1_1 = GUICreate("Add / Remove Members", 669, 433, 196, 128)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("", 8, 8, 324, 185)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelCpname = GUICtrlCreateLabel("CP Name:", 16, 32, 81, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputCpname = GUICtrlCreateInput("", 16, 56, 129, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$LabelLocalGroups = GUICtrlCreateLabel("Local Groups", 16, 101, 107, 20)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$ComboGroups = GUICtrlCreateCombo("", 16, 157, 298, 25)
GUICtrlSetData(-1, "")
GUICtrlSetBkColor(-1, 0xFFFF00)
$ButtonReadGroups = GUICtrlCreateButton("read local Groups", 160, 56, 130, 25)
$ButtonReadmembers = GUICtrlCreateButton("read Members", 16, 125, 130, 25)
$IconReadLocalGroups = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 300, 60, 16, 16)
$IconReadMembers = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 155, 130, 16, 16)
$Status = GUICtrlCreateLabel("Status", 150, 115, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Statu = GUICtrlCreateLabel("Status", 295, 45, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("User", 8, 210, 324, 109)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelUserID = GUICtrlCreateLabel("User ID:", 16, 259, 66, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputComputer = GUICtrlCreateInput("", 88, 251, 89, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$ButtonAdd = GUICtrlCreateButton("Add User", 184, 236, 100, 25)
$ButtonRemove = GUICtrlCreateButton("Remove user", 184, 273, 100, 25)
$IconAddUser = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 295, 240, 16, 16)
$IconRemoveUser = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 295, 280, 16, 16)
$Label1 = GUICtrlCreateLabel("Status", 290, 225, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("Status", 290, 265, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListMembers = GUICtrlCreateList("", 339, 31, 325, 383)
GUICtrlSetData(-1, "")
$LabelMembersof = GUICtrlCreateLabel("Members of Group", 345, 10, 121, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Pic1 = GUICtrlCreatePic("C:\temp\user-management-.jpg", 110, 330, 94, 87)
GUISetState(@SW_SHOW)



While 1
    $msg = GUIGetMsg()
    Select
        ;Case $GUI_EVENT_CLOSE
             Case $msg = $GUI_EVENT_CLOSE
            Exitloop


         Case $msg = $ButtonReadGroups
            ;MsgBox(0, "Note", "Button 'read Groups' not work !")

      $CPname = GuiCtrlRead($inputCpname)

            If $CPname = "" Then
                MsgBox(16, "Error", "Missing Computer Nr. ")
                   Else

         $aGroups = _LocalAccounts_GetGroupList($CPname)
       ;_ArrayDisplay($aGroups)

         Func _LocalAccounts_GetGroupList($sComputerName = $CPname)
         Local $aFilter = ["group"], $aResult[1], $oGroup

         Local $oComputer = ObjGet("WinNT://" & $CPname)

   If NOT IsObj($oComputer) Then Return SetError(1, 0, 0)

    $oComputer.Filter = $aFilter
    For $oGroup In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oGroup.Name
    Next
    $aResult[0] = UBound($aresult) - 1
    _ArrayDelete($aResult, 0)

  GUICtrlSetData($ComboGroups, _ArrayToString($aResult))

    Return $aResult
EndFunc

endif


         Case $msg = $ButtonReadmembers
            ;MsgBox(0, "Note", "Button 'Read Members' not work !")

       Local $readCombo = GuiCtrlRead($ComboGroups)

            If $readCombo = "" Then
                MsgBox(16, "Error", "no Group Selected ! ")
             Else

$CPname = GuiCtrlRead($inputCpname)

$aUsers = _LocalAccounts_GetUserList($CPname)
_ArrayDisplay($aUsers)

Func _LocalAccounts_GetUserList($sComputername = $cpname)
    Local $aFilter= ["user"], $aResult[1], $oUser

    Local $oComputer = ObjGet("WinNT://" & $CPname & "\" & $readCombo)

    $oComputer.Filter = $aFilter
    For $oUser In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oUser.Name
    Next
    $aResult[0] = UBound($aresult) - 1
    _ArrayDelete($aResult, 0)
  GUICtrlSetData($ListMembers, _ArrayToString($aResult))
    Return $aResult
EndFunc
endif
         Case $msg = $ButtonAdd
            MsgBox(0, "Note", "Button 'Add User' not working !")


         Case $msg = $ButtonRemove
            MsgBox(0, "Note", "Button 'Remove User' not working !")

;RunWait(@ComSpec & ' /c Net Localgroup Administrators ' & @UserName & ' /Delete')


    EndSelect
 WEnd

 func terminate()                                                                     ;exit
    Exit 0
EndFunc

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Here are some corrections (functions cannot be declared in a block of code)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here


#Include <Array.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


$Form1_1 = GUICreate("Add / Remove Members", 669, 433, 196, 128)
GUISetBkColor(0xFFFFFF)
$Group1 = GUICtrlCreateGroup("", 8, 8, 324, 185)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelCpname = GUICtrlCreateLabel("CP Name:", 16, 32, 81, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputCpname = GUICtrlCreateInput("", 16, 56, 129, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$LabelLocalGroups = GUICtrlCreateLabel("Local Groups", 16, 101, 107, 20)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$ComboGroups = GUICtrlCreateCombo("", 16, 157, 298, 25)
GUICtrlSetData(-1, "")
GUICtrlSetBkColor(-1, 0xFFFF00)
$ButtonReadGroups = GUICtrlCreateButton("read local Groups", 160, 56, 130, 25)
$ButtonReadmembers = GUICtrlCreateButton("read Members", 16, 125, 130, 25)
$IconReadLocalGroups = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 300, 60, 16, 16)
$IconReadMembers = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 155, 130, 16, 16)
$Status = GUICtrlCreateLabel("Status", 150, 115, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Statu = GUICtrlCreateLabel("Status", 295, 45, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("User", 8, 210, 324, 109)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
$LabelUserID = GUICtrlCreateLabel("User ID:", 16, 259, 66, 23)
GUICtrlSetFont(-1, 12, 800, 0, "Arial")
$InputComputer = GUICtrlCreateInput("", 88, 251, 89, 30)
GUICtrlSetFont(-1, 14, 800, 0, "Arial")
$ButtonAdd = GUICtrlCreateButton("Add User", 184, 236, 100, 25)
$ButtonRemove = GUICtrlCreateButton("Remove user", 184, 273, 100, 25)
$IconAddUser = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 295, 240, 16, 16)
$IconRemoveUser = GUICtrlCreateIcon("C:\temp\work_ICONS\Yell_On_B.ico", -1, 295, 280, 16, 16)
$Label1 = GUICtrlCreateLabel("Status", 290, 225, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel("Status", 290, 265, 32, 15)
GUICtrlSetFont(-1, 7, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ListMembers = GUICtrlCreateList("", 339, 31, 325, 383)
GUICtrlSetData(-1, "")
$LabelMembersof = GUICtrlCreateLabel("Members of Group", 345, 10, 121, 20)
GUICtrlSetFont(-1, 10, 800, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
$Pic1 = GUICtrlCreatePic("C:\temp\user-management-.jpg", 110, 330, 94, 87)
GUISetState(@SW_SHOW)



While 1
    $msg = GUIGetMsg()
    Select
        ;Case $GUI_EVENT_CLOSE
        Case $msg = $GUI_EVENT_CLOSE
            Exitloop
        Case $msg = $ButtonReadGroups
            ;MsgBox(0, "Note", "Button 'read Groups' not work !")
            $CPname = GuiCtrlRead($inputCpname)
            If $CPname = "" Then
                MsgBox(16, "Error", "Missing Computer Nr. ")
            Else
                $aGroups = _LocalAccounts_GetGroupList($CPname)
            Endif

         Case $msg = $ButtonReadmembers
            ;MsgBox(0, "Note", "Button 'Read Members' not work !")

            Local $readCombo = GuiCtrlRead($ComboGroups)

            If $readCombo = "" Then
                MsgBox(16, "Error", "no Group Selected ! ")
            Else
                $CPname = GuiCtrlRead($inputCpname)

                $aUsers = _LocalAccounts_GetUserList($CPname)
                _ArrayDisplay($aUsers)
            EndIf
            
        Case $msg = $ButtonAdd
            MsgBox(0, "Note", "Button 'Add User' not working !")

        Case $msg = $ButtonRemove
            MsgBox(0, "Note", "Button 'Remove User' not working !")
            ;RunWait(@ComSpec & ' /c Net Localgroup Administrators ' & @UserName & ' /Delete')

    EndSelect
 WEnd
 
Func _LocalAccounts_GetUserList($sComputername = @ComputerName)
    Local $aFilter= ["user"], $aResult[1], $oUser
    Local $oComputer = ObjGet("WinNT://" & $sComputername)
    If NOT IsObj($oComputer) Then Return SetError(1, 0, 0)

    $oComputer.Filter = $aFilter
    For $oUser In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oUser.Name
    Next
    $aResult[0] = UBound($aresult) - 1
    _ArrayDelete($aResult, 0)
    GUICtrlSetData($ListMembers, _ArrayToString($aResult))
    Return $aResult
EndFunc


 
Func _LocalAccounts_GetGroupList($sComputerName = @ComputerName)
    Local $aFilter = ["group"], $aResult[1], $oGroup
    Local $oComputer = ObjGet("WinNT://" & $sComputerName)
    If NOT IsObj($oComputer) Then Return SetError(1, 0, 0)

    $oComputer.Filter = $aFilter
    For $oGroup In $oComputer
        Redim $aResult[ UBound($aResult) + 1]
        $aResult[ UBound($aResult) - 1] = $oGroup.Name
    Next
    $aResult[0] = UBound($aresult) - 1
    _ArrayDelete($aResult, 0)

    GUICtrlSetData($ComboGroups, _ArrayToString($aResult))

    Return $aResult
EndFunc
 
 
 

 func terminate()                                                                     ;exit
    Exit 0
EndFunc

Edit : look at the Local account UDF : https://www.autoitscript.com/forum/topic/74118-local-account-udf/

 

Edited by jguinch

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

thanks again jguinch :)

Edited by kneze

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

    • Ian_Mac
      By Ian_Mac
      hello, i just wanted to ask if how........
       I have a gui combo box with a list and i wanted it to remember the last item that i selected, that when i close the gui and then open the gui again, my last selected item will be automatically show in the combobox as selected item already.
      thank you in advance.
    • argumentum
      By argumentum
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <Array.au3> #include <WinAPITheme.au3> #include <GDIPlus.au3> #Region GUICtrlComboSetColors UDF Global $g__aWM_CTLCOLORLISTBOX[1][16] = [[0, 0, 0]] ; init. the Global array ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors ; Description ...: Change the colors and position/size of a ComboBox ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iBgColor = Default] [, $iFgColor = Default] [, $iExtendLeft = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iBgColor - Background RGB color ; - or "-1" to use prior color declared ; - or to remove a control by ControlID, "-2" ; - or to remove a control by ArrayIndex, "-3" ; $iFgColor - Foreground RGB color ; - or "-1" to use prior color declared ; - or "-2" to use sytem color and leave theme default ; $iExtendLeft - pixels to extend the dropdown list ; - or "-1" to use prior width declared ; - or "1" auto size, extending left ( see Remarks/AutoSize ) ; - or "2" auto size, extending right ( see Remarks/AutoSize ) ; Return values .: Success - index position in the array ; Failure - 0 ; @error - 1 : Control handle = 0 ; - 2 : GetComboBoxInfo failed ; - 3 : Control for removal not found ; @extended - 2 : Success on Control removal ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; AutoSize...: use the pertinent parameters from GUICtrlComboSetColors_SetAutoSize() ; minus the CtrlID as semicolon separated to initialize. Ex: "2;Arial;8.5;0" ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors($idCombo = 0, $iBgColor = Default, $iFgColor = Default, $iExtendLeft = Default) If Not $idCombo Then Return SetError(1, 0, 0) Local $n, $tInfo, $i = 0 If $iBgColor = -2 Or $iBgColor = -3 Then Local $m For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If ($g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo And $iBgColor = -2) Or ($g__aWM_CTLCOLORLISTBOX[$n][9] = $idCombo And $iBgColor = -3) Then _ArrayDelete($g__aWM_CTLCOLORLISTBOX, $n) $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(0, 2, $n) EndIf Next Return SetError(3, 0, 0) EndIf For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then $i = $n ExitLoop EndIf Next If Not $i Then $g__aWM_CTLCOLORLISTBOX[0][0] += 1 $i = $g__aWM_CTLCOLORLISTBOX[0][0] ; If $i >= UBound($g__aWM_CTLCOLORLISTBOX) Then ReDim $g__aWM_CTLCOLORLISTBOX[$i + 1][16] ; add extra "slots" EndIf EndIf Local $sStr = GUICtrlRead($idCombo) Local $iSetWindowTheme = 1 If $iBgColor = Default And $iFgColor = Default Then $iSetWindowTheme = 0 If $iBgColor = Default Then $iBgColor = _WinAPI_GetSysColor($COLOR_WINDOW) If $iFgColor = Default Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) If $iBgColor = -1 Then $iBgColor = $g__aWM_CTLCOLORLISTBOX[$i][10] If $iFgColor = -1 Then $iFgColor = $g__aWM_CTLCOLORLISTBOX[$i][11] $g__aWM_CTLCOLORLISTBOX[$i][11] = $iFgColor $g__aWM_CTLCOLORLISTBOX[$i][10] = $iBgColor If $iExtendLeft = Default Then $iExtendLeft = 0 $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf If $iExtendLeft = -1 Then $iExtendLeft = $g__aWM_CTLCOLORLISTBOX[$i][8] ElseIf Int($iExtendLeft) = 1 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 1 ElseIf Int($iExtendLeft) = 2 Then $g__aWM_CTLCOLORLISTBOX[$i][12] = 2 Else $g__aWM_CTLCOLORLISTBOX[$i][12] = 0 EndIf $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($iExtendLeft) $g__aWM_CTLCOLORLISTBOX[$i][0] = $idCombo $g__aWM_CTLCOLORLISTBOX[$i][1] = GUICtrlGetHandle($idCombo) $g__aWM_CTLCOLORLISTBOX[$i][13] = "Arial" ; default $sFont $g__aWM_CTLCOLORLISTBOX[$i][14] = 8.5 ; default $fSize $g__aWM_CTLCOLORLISTBOX[$i][15] = 0 ; default $iStyle If $g__aWM_CTLCOLORLISTBOX[$i][12] Then $f = StringSplit($iExtendLeft, ";") If UBound($f) > 1 Then $g__aWM_CTLCOLORLISTBOX[$i][8] = Int($f[1]) If UBound($f) > 2 Then $g__aWM_CTLCOLORLISTBOX[$i][13] = $f[2] If UBound($f) > 3 Then $g__aWM_CTLCOLORLISTBOX[$i][14] = Int($f[3]) If UBound($f) > 4 Then $g__aWM_CTLCOLORLISTBOX[$i][15] = Int($f[4]) $t = TimerInit() GUICtrlComboSetColors_SetAutoSize(Int("-" & $i), $g__aWM_CTLCOLORLISTBOX[$i][12], $g__aWM_CTLCOLORLISTBOX[$i][13], $g__aWM_CTLCOLORLISTBOX[$i][14], $g__aWM_CTLCOLORLISTBOX[$i][15]) ConsoleWrite(TimerDiff($t) & @CRLF) EndIf If _GUICtrlComboBox_GetComboBoxInfo($idCombo, $tInfo) Then If $iSetWindowTheme Then If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], "", "") If $g__aWM_CTLCOLORLISTBOX[$i][11] <> -2 Then GUICtrlSetColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iFgColor) GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], $iBgColor) Else GUICtrlSetBkColor($g__aWM_CTLCOLORLISTBOX[$i][0], _WinAPI_GetSysColor($COLOR_HOTLIGHT)) _WinAPI_SetWindowTheme($g__aWM_CTLCOLORLISTBOX[$i][1], 0, 0) EndIf $g__aWM_CTLCOLORLISTBOX[$i][2] = DllStructGetData($tInfo, "hCombo") $g__aWM_CTLCOLORLISTBOX[$i][3] = DllStructGetData($tInfo, "hEdit") $g__aWM_CTLCOLORLISTBOX[$i][4] = DllStructGetData($tInfo, "hList") ; this is what is colored Else $g__aWM_CTLCOLORLISTBOX[0][0] -= 1 Return SetError(2, 0, 0) EndIf If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) $g__aWM_CTLCOLORLISTBOX[$i][5] = 0 ; holder for "_WinAPI_CreateSolidBrush()" return value $g__aWM_CTLCOLORLISTBOX[$i][6] = BitOR(BitAND($iBgColor, 0x00FF00), BitShift(BitAND($iBgColor, 0x0000FF), -16), BitShift(BitAND($iBgColor, 0xFF0000), 16)) If $g__aWM_CTLCOLORLISTBOX[$i][11] = -2 Then $iFgColor = _WinAPI_GetSysColor($COLOR_WINDOWTEXT) $g__aWM_CTLCOLORLISTBOX[$i][7] = BitOR(BitAND($iFgColor, 0x00FF00), BitShift(BitAND($iFgColor, 0x0000FF), -16), BitShift(BitAND($iFgColor, 0xFF0000), 16)) If Not $g__aWM_CTLCOLORLISTBOX[0][1] Then If $g__aWM_CTLCOLORLISTBOX[$i][4] Then $g__aWM_CTLCOLORLISTBOX[0][1] = GUIRegisterMsg($WM_CTLCOLORLISTBOX, "UDF_WM_CTLCOLORLISTBOX") If $g__aWM_CTLCOLORLISTBOX[0][1] Then OnAutoItExitRegister("OnAutoItExit_UDF_WM_CTLCOLORLISTBOX") EndIf EndIf $g__aWM_CTLCOLORLISTBOX[0][2] += 1 $g__aWM_CTLCOLORLISTBOX[$i][9] = $g__aWM_CTLCOLORLISTBOX[0][2] ; internal ID $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() ; to use in UDF_WM_CTLCOLORLISTBOX() $g__aWM_CTLCOLORLISTBOX[0][4] = 0 ; to use in UDF_WM_CTLCOLORLISTBOX() If $sStr Then GUICtrlSetData($idCombo, $sStr) Return SetError(0, 0, $g__aWM_CTLCOLORLISTBOX[0][2]) EndFunc ;==>GUICtrlComboSetColors Func UDF_WM_CTLCOLORLISTBOX($hWnd, $Msg, $wParam, $lParam) ConsoleWrite('+ Func UDF_WM_CTLCOLORLISTBOX(' & $hWnd & ', ' & $Msg & ', ' & $wParam & ', ' & $lParam & ')' & @CRLF) For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$i][4] = $lParam Then If TimerDiff($g__aWM_CTLCOLORLISTBOX[0][3]) > 500 Or $g__aWM_CTLCOLORLISTBOX[0][4] <> $lParam Then If $g__aWM_CTLCOLORLISTBOX[$i][12] Then GUICtrlComboSetColors_SetAutoSize("-" & $i) EndIf $g__aWM_CTLCOLORLISTBOX[0][3] = TimerInit() $g__aWM_CTLCOLORLISTBOX[0][4] = $lParam If $g__aWM_CTLCOLORLISTBOX[$i][8] > 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0] - $g__aWM_CTLCOLORLISTBOX[$i][8], $aWPos[1] + $aWPos[3], $aWPos[2] + $g__aWM_CTLCOLORLISTBOX[$i][8]) ElseIf $g__aWM_CTLCOLORLISTBOX[$i][8] < 0 Then Local $aWPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$i][2]) WinMove($lParam, "", $aWPos[0], $aWPos[1] + $aWPos[3], $aWPos[2] - $g__aWM_CTLCOLORLISTBOX[$i][8]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][7] >= 0 Then _WinAPI_SetTextColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][7]) EndIf If $g__aWM_CTLCOLORLISTBOX[$i][6] >= 0 Then _WinAPI_SetBkColor($wParam, $g__aWM_CTLCOLORLISTBOX[$i][6]) If Not $g__aWM_CTLCOLORLISTBOX[$i][5] Then $g__aWM_CTLCOLORLISTBOX[$i][5] = _WinAPI_CreateSolidBrush($g__aWM_CTLCOLORLISTBOX[$i][6]) Return $g__aWM_CTLCOLORLISTBOX[$i][5] EndIf Return 0 EndIf Next EndFunc ;==>UDF_WM_CTLCOLORLISTBOX ; #FUNCTION# ==================================================================================================================== ; Name...........: GUICtrlComboSetColors_SetAutoSize ; Description ...: Set autosize for a ComboBox initialized in GUICtrlComboSetColors() ; Syntax.........: GUICtrlComboSetColors ( $idCombo [, $iExtendLeft = Default] [, $sFont = Default] [, $fSize = Default] [, $iStyle = Default] ) ; Parameters ....: $idCombo - GUICtrlCreateCombo() ControlID / [ ArrayIndex ] ; $iExtendLeft - 1 = Left, 2 = Right, 0 = disable auto-sizing ; $sFont - Font name ; $fSize - Font size ; $iStyle - Font style ; Return values .: Success - widthest string in pixels ; Failure - -1 ; @error - look at the comments in the function ; Author ........: argumentum ; Modified.......: v0.0.0.5 ; Remarks .......: this UDF is in its a work in progress, will expand if needed. ; Related .......: GUICtrlComboSetColors() ; Link ..........: https://www.autoitscript.com/forum/topic/191035-combobox-set-dropdownlist-bgcolor/ ; Example .......: Yes, at the end of the file ; =============================================================================================================================== Func GUICtrlComboSetColors_SetAutoSize($idCombo, $iExtendLeft = Default, $sFont = Default, $fSize = Default, $iStyle = Default) ConsoleWrite('+ Func GUICtrlComboSetColors_AutoSizeSet("' & $idCombo & '", "' & $iExtendLeft & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '")' & @CRLF) $idCombo = Int($idCombo) ; just in case the value is a string Local $n, $iArrayIndex = 0, $iCtrl = 0 If $idCombo > 0 Then For $n = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If $g__aWM_CTLCOLORLISTBOX[$n][0] = $idCombo Then ; the expected value, is the ControlID $iArrayIndex = $n ExitLoop EndIf Next Return SetError(4, 0, -1) ; $iArrayIndex not found ElseIf $idCombo < 0 Then ; the expected value, is a negative of array's index .. $iArrayIndex = Int(StringTrimLeft(StringStripWS($idCombo, 8), 1)) ; .. so now is a positive value .. If $iArrayIndex < 1 Then Return SetError(3, 0, -1) ; .. else, error .. If $iArrayIndex > $g__aWM_CTLCOLORLISTBOX[0][0] Then Return SetError(2, 0, -1) ; .. as long as is not greater than expected Else Return SetError(1, 0, -1) ; could not find a usable value EndIf Switch $iExtendLeft Case 0, 1, 2 $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = $iExtendLeft EndSwitch Local $aCtrlPos = WinGetPos($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][1]) If UBound($aCtrlPos) <> 4 Then Return SetError(5, 0, -1) ; could not get a usable value Local $sString = StringReplace(_GUICtrlComboBox_GetList($g__aWM_CTLCOLORLISTBOX[$iArrayIndex][0]), "|", @CRLF) Local $aStrWidth = _GDIPlus_MeasureString($sString, $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][13], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][14], $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][15]) If UBound($aStrWidth) <> 2 Then Return SetError(6, 0, -1) ; could not get a usable value If $aStrWidth[0] < $aCtrlPos[2] Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = 0 Else $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = $aStrWidth[0] - $aCtrlPos[2] If $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][12] = 2 Then $g__aWM_CTLCOLORLISTBOX[$iArrayIndex][8] = Int("-" & $aStrWidth[0] - $aCtrlPos[2]) EndIf Return $aStrWidth[0] EndFunc ;==>GUICtrlComboSetColors_SetAutoSize Func _GDIPlus_MeasureString($sString, $sFont = "Arial", $fSize = 12, $iStyle = 0, $bRound = True) ConsoleWrite('Func _GDIPlus_MeasureString("' & $sString & '", "' & $sFont & '", "' & $fSize & '", "' & $iStyle & '", "' & $bRound & '")' & @CRLF) ; original code @ https://www.autoitscript.com/forum/topic/150736-gdi-wrapping-text/?do=findComment&comment=1077210 If Not $__g_iGDIPRef Then _GDIPlus_Startup() ; added by argumentum for this UDF's implementation ( AutoIt v3.3.14 ) due to the way the function is written ;~ Func _GDIPlus_Startup($sGDIPDLL = Default, $bRetDllHandle = False) ;~ $__g_iGDIPRef += 1 <-- I believe this aspect should be coded differently in "GDIPlus.au3" ;~ If $__g_iGDIPRef > 1 Then Return True Local $aSize[2] Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) If Not $hFamily Then Return SetError(1, 0, $aSize) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFont = _GDIPlus_FontCreate($hFamily, $fSize, $iStyle) Local Const $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0) Local Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND(0) Local $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sString, $hFont, $tLayout, $hFormat) $aSize[0] = $bRound ? Round($aInfo[0].Width, 0) : $aInfo[0].Width $aSize[1] = $bRound ? Round($aInfo[0].Height, 0) : $aInfo[0].Height _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphic) Return $aSize EndFunc ;==>_GDIPlus_MeasureString Func OnAutoItExit_UDF_WM_CTLCOLORLISTBOX() For $i = 1 To $g__aWM_CTLCOLORLISTBOX[0][0] If Int($g__aWM_CTLCOLORLISTBOX[$i][5]) Then _WinAPI_DeleteObject($g__aWM_CTLCOLORLISTBOX[$i][5]) Next If $__g_iGDIPRef Then _GDIPlus_Shutdown() EndFunc ;==>OnAutoItExit_UDF_WM_CTLCOLORLISTBOX #EndRegion GUICtrlComboSetColors UDF Example() Func Example() ; Create GUI GUICreate("ComboBox Set DROPDOWNLIST BgColor", 640, 300) Local $a_idCombo[7] = [6] $a_idCombo[1] = GUICtrlCreateCombo("", 2, 2, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[1], 0xEEEEEE, -2, Default) Example_FillTheCombo($a_idCombo[1]) GUICtrlCreateLabel("<<< change BG color, default theme && size ", 400, 4, 396, 296) $a_idCombo[2] = GUICtrlCreateCombo("", 2, 32, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[2], 0x0000FF, 0xFFFF00, 0) Example_FillTheCombo($a_idCombo[2]) GUICtrlCreateLabel("<<< change colors", 400, 34, 396, 296) $a_idCombo[3] = GUICtrlCreateCombo("", 2, 62, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[3], 0xdddddd, Default, 100) Example_FillTheCombo($a_idCombo[3]) GUICtrlCreateLabel("<<< change BG color, resize 100px. left", 400, 64, 396, 296) $a_idCombo[4] = GUICtrlCreateCombo("", 2, 92, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[4], Default, 0x0000FF, -100) Example_FillTheCombo($a_idCombo[4]) GUICtrlCreateLabel("<<< change FG color, resize 100px. right", 400, 94, 396, 296) $a_idCombo[5] = GUICtrlCreateCombo("", 2, 122, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlComboSetColors($a_idCombo[5], 0x00FFFF, 0x0000FF, 1) Example_FillTheCombo($a_idCombo[5]) GUICtrlCreateLabel("<<< change colors, resize auto left", 400, 124, 396, 296) $a_idCombo[6] = GUICtrlCreateCombo("", 2, 152, 390, 296, BitOR($CBS_DROPDOWNLIST, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($a_idCombo[6], 10, 400, 0, "Courier New") GUICtrlComboSetColors($a_idCombo[6], Default, Default, "2;Courier New;10") Example_FillTheCombo($a_idCombo[6]) GUICtrlCreateLabel("<<< default colors, resize auto right", 400, 154, 396, 296) Local $bttnArrayShow = GUICtrlCreateButton("Show array", 2, 296 - 27, 75, 25) Local $bttnStrMore = GUICtrlCreateButton("Longer str.", 102, 296 - 27, 75, 25) Local $idLorem = GUICtrlCreateLabel("", 195, 296 - 27, 50, 25) Local $bttnStrLess = GUICtrlCreateButton("Shorter str.", 252, 296 - 27, 75, 25) GUISetState(@SW_SHOW) WinActivate("ComboBox Set DROPDOWNLIST BgColor") ;~ Sleep(3500) ; you can reassign colors, size, or restore default ;~ GUICtrlComboSetColors($idCombo5, Default, Default, 300) ; this resets the Control back to default and changes $iExtendLeft ;~ GUICtrlComboSetColors($idCombo5, 0x0000FF, 0x00FFFF, -1) ; this changes the colors and keeps $iExtendLeft as it was ;~ GUICtrlComboSetColors($idCombo5, -1, -1, 300) ; using "-1" will keep the existing colors ;~ ; so in this case, only the $iExtendLeft is declared ;~ Example_FillTheCombo($idCombo5) ;~ Sleep(500) ; after removal, it will not repaint "hList", but then again, you're deleteing the control ;~ GUICtrlComboSetColors($idColors, -3) ;~ GUICtrlDelete($idCombo2) Local $iLorem = 5, $sLorem = "" Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) ; Loop until the user exits. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete() Return Case $bttnArrayShow _ArrayDisplay($g__aWM_CTLCOLORLISTBOX, "$g__aWM_CTLCOLORLISTBOX") Case $bttnStrMore $iLorem += 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) Case $bttnStrLess $iLorem -= 5 Example_LoremStr($iLorem, $sLorem, $a_idCombo, $idLorem) EndSwitch WEnd EndFunc ;==>Example Func Example_FillTheCombo(ByRef $idComboCtrl) GUICtrlSetData($idComboCtrl, "") _GUICtrlComboBox_AddString($idComboCtrl, "something") _GUICtrlComboBox_AddString($idComboCtrl, "something else") _GUICtrlComboBox_AddString($idComboCtrl, "blah, blah, blah, blah") _GUICtrlComboBox_AddString($idComboCtrl, "Lorem will change") Local $a = _GUICtrlComboBox_GetListArray($idComboCtrl) GUICtrlSetData($idComboCtrl, $a[1]) EndFunc ;==>Example_FillTheCombo Func Example_LoremStr(ByRef $iLorem, ByRef $sLorem, ByRef $a_idCombo, ByRef $idLorem) Local Static $s = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat." $s &= " Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat." Local Static $i = 5, $a = StringSplit($s, " ") If $iLorem < 1 Then $iLorem = 1 If $iLorem > $a[0] Then $iLorem = $a[0] Local $x, $iLastEntry $sLorem = "" GUICtrlSetData($idLorem, $iLorem & ' words') For $x = 1 To $iLorem $sLorem &= $a[$x] & " " Next For $x = 1 To $a_idCombo[0] $iLastEntry = _GUICtrlComboBox_GetCount($a_idCombo[$x]) - 1 _GUICtrlComboBox_DeleteString($a_idCombo[$x], $iLastEntry) _GUICtrlComboBox_AddString($a_idCombo[$x], $sLorem) Next EndFunc ;==>Example_LoremStr new in v0.0.0.5: auto size the dropdown.
    • kcvinu
      By kcvinu
      Hi all,
      How can i get notified when user clicks on a combo box's edit area ? This is my code so far. 
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <ComboConstants.au3> #include <ListBoxConstants.au3> Global $btn ; creates a window Global $Window_0 = GUICreate("My Window", 800, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX)) $btn = GUICtrlCreateButton("Click Me", 50, 50, 120, 50) Global $cmb = GUICtrlCreateCombo("Sample", 50, 150, 300, 50) GUICtrlSetFont(-1,12,400) Global $lstbx = GUICtrlCreateList("FirstItem", 400,50, 200, 300) GUICtrlSetFont(-1,12,400) GUIRegisterMsg($WM_COMMAND, "MyEventCallback") GUIRegisterMsg($WM_SIZE, "MyEventCallback") GUIRegisterMsg($WM_NOTIFY, "NotifyManager") GUISetState(@SW_SHOW) GUICtrlSetData($cmb, "Item 2|Item 3", "Item 2") GUICtrlSetData($lstbx, "Apple|Orange|Pineapple|Grape|Lemon") Do $Event = GUIGetMsg( ) Until $Event = $GUI_EVENT_CLOSE Func MyEventCallback($hwnd, $message, $wParam, $lParam) Select Case $message = $WM_COMMAND ;---------------------------------------------------------------- If LoWord($wParam) = $cmb Then ; if control id is combox's Then Local $Notification = HiWord($wParam) Select Case $Notification = $CBN_DROPDOWN ; here we check the notification code. ConsoleWrite("$CBN_DROPDOWN Worked " & @MIN & ":" & @SEC & @CRLF) Case $Notification = $CBN_EDITCHANGE ; here we check the notification code. ConsoleWrite("$CBN_EDITCHANGE Worked " & @MIN & ":" & @SEC & @CRLF) ; **** Here i want add the code for combo box clicking. EndSelect ;--------------------------------------------------------------------- ElseIf LoWord($wParam) = $lstbx Then Local $Notification = HiWord($wParam) Select Case $Notification = $LBN_SELCHANGE ConsoleWrite("$LBN_SELCHANGE" & @CRLF) EndSelect EndIf ;------------------------------------------------------------------ Case $message = $WM_SIZE EndSelect Return $GUI_RUNDEFMSG EndFunc ;==>ProGUI_EventCallback Func NotifyManager($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ;Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If DllStructGetData($tagNMHDR, 3) = $NM_LDOWN Then ConsoleWrite("Notify Worked" & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc Func LoWord($Variable) Return BitAND($Variable, 0xFFFF) EndFunc Func HiWord($Variable) Return BitShift($Variable, 16) EndFunc  
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning
      I'm working on a little project, and I was wondering if there's a way ( sure there is ) to insert data to a ComboBox control everytime the user insert some text in the ComboBox which is not in the ComboBox data. I'll try to explain with an example:
      - Form with some data ( ComboBox is empty );
      - User prompt something in the ComboBox: if what the user prompts is not in the ComboBox values ( at the moment empty ), then insert the value in the ComboBox values, in order to have, next time the user prompts the form, the value that he entered.
      More pratical example:
      - First call of the form, ComboBox empty;
      - I prompt "A" in the ComboBox;
      - Second call, in the ComboBox I should see "A";
      - I prompt "B" in the ComboBox;
      - Third call, I should see "A"
                                                 "B";
      - And so on...
      Everytime the form is called, I re-create it, so I think I can't use _GUICtrlComboBox_AddStrings().
      I tried with
      Global $strCboStrings = "" ; When the user prompt the form, the code below is executed. ; I.E. : User prompt "A", after the if I should have "A"; ; In the second call, If I write "B", I should see "A" ; "B"; ; If I write "A" again, in the combobox values should not be any changes. If Not StringInStr($strCboStrings, GUICtrlRead($cboVoiceCategory)) <> 0 Then $strCboStrings &= $strCboStrings & "|" & GUICtrlRead($cboVoiceCategory) EndIf Any suggestion?
      Thanks
    • kstriyhon
      By kstriyhon
      hello Comunity i am new to autoit and i bump into a pitfall regarding the creation of objects in a dinamyc way but more especific  creating combobox at runtime
      i need many comboboxes and sofar i createdthem manually 
      like this 
      $idCombo_1 = GUICtrlCreateCombo("", 500, 40, 130, 21)     $idCombo_2 = GUICtrlCreateCombo("", 500, 70, 130, 21)     $idCombo_3 = GUICtrlCreateCombo("", 500, 100, 130, 21)     $idCombo_4 = GUICtrlCreateCombo("", 500, 130, 130, 21)     $idCombo_5 = GUICtrlCreateCombo("", 500, 160, 130, 21)     $idCombo_6 = GUICtrlCreateCombo("", 500, 190, 130, 21)     $idCombo_7 = GUICtrlCreateCombo("", 500, 220, 130, 21)     $idCombo_8 = GUICtrlCreateCombo("", 500, 250, 130, 21)     $idCombo_9 = GUICtrlCreateCombo("", 500, 280, 130, 21)     GUICtrlSetData($idCombo_1, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_2, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_3, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_4, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_5, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_6, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_7, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_8, "Item1|Item2|Item3|Item4|Item5")     GUICtrlSetData($idCombo_9, "Item1|Item2|Item3|Item4|Item5") now i need this example but create them at runtime as there are more than 9 combos what i need thanks in advance kind regards