Jump to content

read local Groups of remote Computer add to Combobox


kneze
 Share

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
Link to comment
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
Link to comment
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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

Sorry for wrong way posting my code.

You can still edit your post, to fix it.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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

 

Link to comment
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
Link to comment
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
 Share

×
×
  • Create New...