Jump to content
kneze

read local Groups of remote Computer add to Combobox

Recommended Posts

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

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 beginning - communication with GitHub REST API Forum Rules *
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 APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

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) * IE in TaskScheduler

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: 2019-10-01

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 beginning - communication with GitHub REST API Forum Rules *
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 APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

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) * IE in TaskScheduler

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: 2019-10-01

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

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

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 DannyJ
      Hello Forum, 
      I have one special Combo-box [with BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE) ] and if I press one button I want to change the Combo-box's background color, and after I press Button B I want to change it to the basic settings and it not works.
      I wanna do this with one combo-box.
      I have already tried several methods and I tried  GUICtrlComboSetColors that I have found on this forum.
      (But this methods works perfectly with Cobo boxes that don't have BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE). 
      Here is the example code
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= ;$CBS_DROPDOWNLIST ;$GUI_SS_DEFAULT_COMBO $Form1 = GUICreate("Form1", 504, 249, 252, 227) $Combo1 = GUICtrlCreateCombo("", 136, 24, 193, 25,BitOR($CBS_DROPDOWNLIST, $GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; I want to change this special combo's background color if I press button 1 $Button1 = GUICtrlCreateButton("Button1", 112, 96, 75, 25) $Button2 = GUICtrlCreateButton("Button2", 264, 96, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($Combo1," " & "|" & "apple" & "|" & "banana" & "|" & "cherry" ," ") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 GUICtrlSetBkColor($Combo1,0x0078D7) Case $Button2 ;Makes the original bc color GUICtrlSetBkColor($Combo1,0xFFFFFF) EndSwitch WEnd  
      Thanks you in advance your help
    • By Reher
      Hi
      so i ran into a Problem i didn't expect to get stuck on.
      It sounds simple (and probably is) but i can't seem to get it to work
      So i created a Combobox and filled it with some things from an array which worked fine.
      $combobox = GUICtrlCreateCombo($list[0], 160, 200, 265, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GuiCtrlSetData($list, "|" & _ArrayToString($list,Default,1),$list[2]) GUICtrlSetFont(-1, 9, 400, 0, "Arial") Now i want to change the style of the combobox from $CBS_DROPDOWN to $CBS_DROPDOWNLIST via a checkbox.
      $Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 160, 96, 105, 25) Case $Checkbox1 If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then Call ("Read_only") Else Call ("Edit") Endif Func Read_only() GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOWNLIST) EndFunc Func Edit() GUICtrlSetStyle ($Combobox1,something to change it to $CBS_DROPDOW) EndFunc I tried using $CBS_DROPDOWN and $CBS_DROPDOWNLIST but it simply does nothing.
      I also tried $ES_READONLY which kinda worked, it changed the combobox so i couldn't change the input via dropdown anymore but i could still type in it via keyboard (which i dont want).
      It's essential that its Editable but once the checkbox is checked the combobox becomes readonly so you can't type in it anymore but you can still choose between the items in the list. (It does not have to save your current input if you write something in it and then check the Checkbox it would be best if it would simpy jump back to the first item in the list)
      Im sure this is a simple thing but after long google search im tired of my stupidity can someone give me a push in the right direction?
    • By odaylton
      Hello everyone ,
      Text translated from Portuguese by google - please apologize for any errors

      Once again I need a light from the gurus of this wonderful website
      I am fanatic by combobox for its usability but I am not able to uncertain images within lists ...
      I know uncertain icons, and cursors but I am not able to insert gif or jpg images.
      1) How to solve this ...
      2) will the path is to convert gif into bmp and then uncertain ... how to do that?
      #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> ;dados de mouse #include <WinAPIRes.au3> ;COMBO #include <GuiComboBoxEx.au3> ;Fonts #include <FontConstants.au3> ;obter imagem de arquivo #include <GDIPlus.au3> #include <WinAPIGdi.au3> Example() Func Example() Local $hGUI, $hImage, $hCombo, $hFont Local $idListview, $hImage Local $sWow64 = "" Local $Pasta = "C:\WINDOWS\Cursors\3dgarro.cur" Local $PastaROMs = @MyDocumentsDir & "\Stella\ROMs\" ;com barra no final $hGUI = GUICreate("ImageList", 500, 310) GUISetFont(14, 400, 0, "Arial") ;<<<<<<<<<<this does not work for _GUICtrlComboBoxEx_Create $hCombo = _GUICtrlComboBoxEx_Create($hGUI, "", 2, 2, 494, 200) ;GUICtrlSetFont($hCombo, 14, 400, 0, "Arial");<<<<<<<<<<It does not work ; ;Create a handle to a font object $hFont = _WinAPI_CreateFont(30, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial') ;Pass the handle to _WinAPI_SetFont _WinAPI_SetFont($hCombo, $hFont) $idListview = GUICtrlCreateListView("", 2, 50, 494, 250, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER)) GUISetState(@SW_SHOW) ; Initialize GDI+ library _GDIPlus_Startup() ; Load images $hImage = _GUIImageList_Create(120, 70, 6, 2) ;32,32,5,5) ; $DadosCombo = "Escolha|" & _GUIImageList_Add($hImage, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 120, 70)) ;Local $aCursors[] = [32650, 32512, 32515, 32649, 32651, 32513, 32648, 32646, 32643, 32645, 32642, 32644, 32516, 32514] For $i = 1 To 10 $sFile = FileOpenDialog("Please select an image", $PastaROMs, "Image (*.jpg;*.png;*.bmp;*.gif;*.tif)", BitOR($FD_PATHMUSTEXIST, $FD_FILEMUSTEXIST)) If @error Then Exit MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "No image file has been selected", 30) $a = _GDIPlus_BitmapCreateFromFile ($sFile);<<<<< ok If @error Or Not $hImage Then MsgBox(BitOR($MB_TOPMOST, $MB_ICONERROR), "Error", "This file isn't supported by GDIPlus!") Else $b=_GUIImageList_Add($hImage, $a);<<<<<< Return -1 $DadosCombo &= "|" & $i & "_img_princ.gif""|" & $b EndIf Next _GUICtrlListView_SetImageList($idListview, $hImage, 1) _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage) ; Add columns _GUICtrlListView_AddColumn($idListview, "Icons - Mouses", 350) ; Add items $a = StringSplit($DadosCombo, "|") For $i = 1 To $a[0] Step 2 _GUICtrlListView_AddItem($idListview, $a[$i], $a[$i + 1]) _GUICtrlComboBoxEx_AddString($hCombo, $a[$i], $a[$i + 1], $a[$i + 1]) Next ;AutoIt_Debugger_Command:Disable_Debug ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() ;AutoIt_Debugger_Command:Enable_Debug EndFunc ;==>Example tks
    • By aiter
      I  possibly misunderstood the value of combo boxes, but I thought you could type a value, press enter and the combo box would store that value.
      The reason for wanting this is to store a history of typed commands into the combo box (accepted by pressing enter).
       
      After hours of trying to trap enter on a combobox I realized that the enter event was not registering.
      I had code like this (which used to work on a input box), but it does not for a combobox (because it does not accept enter)
      unc WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) If $hWnd = $CmdForm Then If $nID = $ComboInput Then ; useed to work on a normal input box If _IsPressed('0D') Then ; enter was pressed, respond DoCmd() Anyone able to help?
    • By Grasoft
      Greetings everyone,
      I'm writing a software that edit an ini file section by section with adding/renaming abilities
      but whenever I manually change the combobox to value other than constducted previously, I cannot get this value.
      THIS is a clean version of the code:
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel $secno=GUICtrlRead($SecSel) queysecs() Filledit() Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save And this is with som test msg boxes to know how to get it
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiStatusBar.au3> #include <GuiEdit.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=C:\Program Files (x86)\AutoIt3\SciTE\Koda\Forms\QuickRepEditList7.kxf $SecMgr = GUICreate("Sections Manager", 1159, 690) GUISetFont(12, 800, 0, "MS Sans Serif") $EditSec = GUICtrlCreateEdit("", 45, 45, 1090, 644, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $ES_NOHIDESEL)) $Edit2 = GUICtrlCreateEdit("", 11, 45, 33, 617, BitOR($ES_RIGHT, $ES_READONLY, $ES_WANTRETURN)) GUICtrlSetData(-1, StringFormat(" 1:\r\n 2:\r\n 3:\r\n 4:\r\n 5:\r\n 6:\r\n 7:\r\n 8:\r\n 9:\r\n10:\r\n11:\r\n12:\r\n13:\r\n14:\r\n15:\r\n16:\r\n17:\r\n18:\r\n19:\r\n20:\r\n21:\r\n22:\r\n23:\r\n24:\r\n25:\r\n26:\r\n27:\r\n28:\r\n29:\r\n30:")) $Label1 = GUICtrlCreateLabel("Select Section:", 7, 13, 126, 24) GUICtrlSetFont(-1, 11, 800, 0, "MS Sans Serif") $Savesec = GUICtrlCreateButton("Save Changes", 375, 7, 129, 33) $NewSec = GUICtrlCreateButton("New Section", 700, 7, 121, 33) $SecDwn = GUICtrlCreateButton("Section Down", 830, 7, 137, 33) $SecUp = GUICtrlCreateButton("Section Up", 980, 7, 129, 33) ;$LineNo = GUICtrlCreateInput("LineNo", 664, 7, 65, 28) $copystrs = GUICtrlCreateButton("*******", 507, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") $HeavySep = GUICtrlCreateButton("====", 581, 7, 73, 33) GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif") Global $SecSel Global $secno Global $secn = "NULLz" Global $sFilePathtemp Global $aArray Global $SecNames Global $secnnew Global $ssecn $SecSel = GUICtrlCreateCombo("", 110, 10, 257, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) queysecs() Filledit() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $secno=GUICtrlRead($SecSel) $changed=0 While 1 $secn = GUICtrlRead($SecSel) ;If $secn <> $secno and $changed=0 Then ; $secns = $secn ; $changed=1 ;EndIf $nMsg = GUIGetMsg() ;MsgBox(4, "TEST1?", $secn) Switch $nMsg Case $GUI_EVENT_CLOSE saveeditedmsg() Exit Case $SecSel ;MsgBox(4, "TEST?", GUICtrlRead($SecSel)) ;MsgBox(4, "TEST1?", $secns) ;MsgBox(4, "TEST2?", $secn) $secno=GUICtrlRead($SecSel) ;saveeditedmsg() queysecs() Filledit() ;$changed=0 Case $Savesec saveeditedmsg() queysecs() Case $NewSec Case $SecDwn Case $SecUp Case $copystrs ClipPut("**************************************************************************************************************************************************************") Case $HeavySep ClipPut("==============================================================================================================================================================") EndSwitch ; MsgBox(4, "TEST2?", $secn) WEnd Func queysecs();query section names $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" $aArray = IniReadSectionNames($sFilePath) $SecNames = $aArray[1] ; MsgBox(4, "test3?", $secn) If $secn = "NULLz" Then $secn = $aArray[1] EndIf If Not @error Then For $i = 2 To $aArray[0] $SecNames = $SecNames & "|" & $aArray[$i] Next GUICtrlSetData($SecSel, "", "") GUICtrlSetData($SecSel, $SecNames, $secn) $secno = $secn ;MsgBox(4, "test4?", $secn) EndIf EndFunc ;==>queysecs Func Filledit(); transfer section values on the edit box GUICtrlSetData($EditSec, "") $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" For $i = 1 To 30 $sRead = IniRead($sFilePath, $secn, $i, "") GUICtrlSetData($EditSec, $sRead & @CRLF, 1) Next GUISetState(@SW_SHOW) EndFunc ;==>Filledit Func saveeditedmsg(); save or rename modified section If $secn <> $secno Then $iMsgBoxAnswer = MsgBox(3, "NEW/RENAME", "Press YES to Add this as NEW section" & @CRLF & "Press NO to rename and save this section from " & $secno & "To" & $secn) Select Case $iMsgBoxAnswer = 6 ;YES $secn = $secno save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn Case 7 ;NO $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" IniRenameSection($sFilePath, $secno, $secn) save($secn) $secn = GUICtrlRead($SecSel) $secno = $secn EndSelect Else $iMsgBoxAnswer = MsgBox(4, "Do you want to save changes to this section", "Save Section: " & $secn) Select Case $iMsgBoxAnswer = 6 ;yes save($secn) EndSelect EndIf EndFunc ;==>saveeditedmsg ;MsgBox(4, "Do you want to add this to Database?",$secn) Func save($ssecn); save edit control to a file and then rewrite modified values by line order. $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_OVERWRITE + $FO_CREATEPATH + $FO_UTF8) $sFilePath = @ScriptDir & "\" & "Txt_Reps.ini" FileWrite($sFilePathtemp, GUICtrlRead($EditSec)) $sFilePathtemp = FileOpen(@ScriptDir & "\" & "tempo.quickrep", $FO_READ + $FO_UTF8) For $i = 1 To 30 $sRead = FileReadLine($sFilePathtemp, $i) IniWrite($sFilePath, $ssecn, $i, $sRead) Next GUISetState(@SW_SHOW) EndFunc ;==>save The ini file withthe au3 attached
      This is how I want: when the user changes the combo, the script will check the text combo. In case of changed text it will ask user if I should rename or add it as a new section and then save. If not changed the text of combo it will ask to save only.
      IF NOT possible, Will it possible with _GUICtrlComboBox__GUICtrlComboBoxEx_Create or _GUICtrlComboBoxEx_Create or not
       
      THANK you very much in advance
      QuickSecEdit.zip
×
×
  • Create New...