Sign in to follow this  
Followers 0
AramisResearch

A Couple of GUI Questions and Some Code to Share

2 posts in this topic

I have attached a lump of code below. It could be kind of handy and you're free to use it or abuse it. I have a couple of problems though, for which I would love some help:

1) I have thrown a bit in the GUI_ENABLE/GUI_DISABLE one particlular CreateInput (Lines 97-102) and it works, but it flickers - cuz it's looping, and checking, I know. But I don't know how to make it better, i.e. not flicker. Any ideas welcome here.

2) When I output status messages I am adding @LF's to my lines, but they are showing up in the edit box as little square widgets. I can't see why. Anyone got any ideas?

Thanks,

-Chris

;============================================
; Includes                          |
;============================================

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <constants.au3>

;============================================
; Declarations                              |
;============================================

Global $PathtoPatch, $PathtoPatchInput, $NativeCheckedInput
Global $Status1, $Status2
Global $Message1 = "Server status messages will appear here." & Chr(10)
Dim $ServerArray[500], $ListItem[500], $Selected[500], $Temp_Index, $FullCommand[500]
Global $CaclsInput, $CmdWindowInput, $CommandParametersInput, $NativeCommand, $StubCommand
Global $UserIDInput, $PasswordInput, $DomainInput

;============================================
; Main                                      |
;============================================

Opt("RunErrorsFatal", 0)
If FileExists("C:\ServerList.txt") Then
    _GUISetup()
Else
    MsgBox(16, "Error!", "You need a server list!")
EndIf
;=========================================================================================
; NOTE:  At the moment this program expects to find a text file listing of the servers   |
; it needs for one of the tabs in C:\.  I will get around to making it more dynamic      |
; later on, perhaps a search of your domain when I figure out how to do that.  For now,  |
; you can just make up some names and make a list.                                       |
;=========================================================================================

;============================================
; _GUISetup                                 |
;============================================

Func _GUISetup()

    $PathtoPatch = "C:\Patches\"
    Local $LineCounter = 1
    Local $listview, $Pressed
    
    $ServerList = FileOpen("C:\ServerList.txt", 0)
    While 1
        $Line = FileReadLine($ServerList)
        If @error = -1 Then ExitLoop
        $ServerArray[$LineCounter] = $Line
        $LineCounter = $LineCounter + 1
    WEnd

    GUICreate("Patch Panel", 900, 500)
    
    $Submit = GUICtrlCreateButton("Submit", 150, 470, 50, 20)
    $Exit = GUICtrlCreateButton("Exit", 225,470, 50, 20)
    $Clear = GUICtrlCreateButton("Clear", 300, 470, 50, 20)
    $Status1 = GUICtrlCreateEdit($Message1, 500, 24, 400, 470, BitOR($ES_READONLY, $ES_LEFT, $ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE, $WS_HSCROLL))
    
    GUICtrlCreateTab(2, 2, 498, 460)
    
        $PatchTab = GUICtrlCreateTabItem("Patches")
            $PathtoPatchLabel = GUICtrlCreateLabel("Path to Executable: ", 10, 30, 125, 18)
            $PathtoPatchInput = GUICtrlCreateInput($PathtoPatch, 130, 30, 100, 18)
            
            $NativeCheckedInput = GUICtrlCreateCheckbox("Use a Native Command (Below)", 130, 55)
            
            $CommandParametersLabel = GUICtrlCreateLabel("Command Parameters:", 10, 80, 125, 18)
            $CommandParametersInput = GUICtrlCreateInput("", 130, 80, 200, 18)
            
            $UserIDLabel = GUICtrlCreateLabel("User ID:", 10, 105, 125,18)
            $UserIDInput = GUICtrlCreateInput(@USERNAME, 130, 105, 200, 18)
            
            $PasswordLabel = GUICtrlCreateLabel("Password:", 10, 130, 125,18)
            $PasswordInput = GUICtrlCreateInput("", 130, 130, 200, 18, $ES_PASSWORD)
            
            $DomainLabel = GUICtrlCreateLabel("Domain/Server:", 10, 155, 125, 18)
            $DomainInput = GUICtrlCreateInput(@LogonDomain, 130, 155, 200, 18)
            
            GUICtrlCreateGroup("Native Commands", 10, 190, 480, 260)
                $CaclsInput = GUICtrlCreateRadio("CACLS", 15, 215)
            ;$CmdWindowInput = GUICtrlCreateRadio("DOS Window", 15, 240)
            GUICtrlCreateGroup("", -99, -99, 1, 1)
            
        $ServerTab = GUICtrlCreateTabItem("Servers")
        
            $ListView = GUICtrlCreateListView("Server List", 10, 60, 400, 200, BitOR($LVS_SHOWSELALWAYS,$LVS_REPORT))       
            For $X = 1 to $LineCounter - 1
                $ListItem[$X] = GUICtrlCreateListViewItem($ServerArray[$X], $ListView)
            Next
            
    GuiSetState()
    
    While 1
        Select
        Case GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED
            GUICtrlSetState($PathtoPatchInput, $GUI_DISABLE)
        Case GUICtrlRead($NativeCheckedInput) = $GUI_UNCHECKED
            GUICtrlSetState($PathtoPatchInput, $GUI_ENABLE)
        EndSelect
        $Pressed = GUIGetMsg()
        Select
        Case $Pressed = $Submit
                $Temp_Index = _GUICtrlListViewGetSelectedIndices($listview, 1)
                If IsArray($Temp_Index) Then
                    GUICtrlSetData($Status1, "OK")
                    For $X = 1 To $Temp_Index[0]
                        $Selected[$X] = _GUICtrlListViewGetItemText($listview, $Temp_Index[$X])
                        _VerifyFunction()
                    Next
                Else
                    $Message1 = $Message1 & "No servers selected.  You must select one from the server list." & @LF
                    GUICtrlSetData($Status1, $Message1)
                EndIf
            Case $Pressed = $GUI_EVENT_CLOSE
                ExitLoop
            Case $Pressed = $Exit
                ExitLoop
            Case $Pressed = $Clear
                $Message1 = ""
                GUICtrlSetData($Status1, $Message1)
        EndSelect
    Wend
            
EndFunc


;============================================
; _VerifyFunction                           |
;============================================

Func _VerifyFunction()
    
    Select
        Case GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED
            Select
                Case GUICtrlRead($CaclsInput) = $GUI_CHECKED
                    $StubCommand = "cacls " & GUICtrlRead($CommandParametersInput)
                    $Message1 = $Message1 & "Command constructed successfully.  " & @LF
                    GUICtrlSetData($Status1, $Message1)
                    _ExecuteFunction()
            ;Case GUICtrlRead($CmdWindowInput) = $GUI_CHECKED
            ;   $StubCommand = "cmd " & GUICtrlRead($CommandParametersInput)
            ;   $Message1 = $Message1 & "Command contructed successfully." & @LF
            ;   _ExecuteFunction()
                Case Else
                    $Message1 = $Message1 & "You need to select a native command or clear the checkbox and type one in." & @LF
                    GUICtrlSetData($Status1, $Message1)
            EndSelect
        Case GUICtrlRead($NativeCheckedInput) = $GUI_UNCHECKED
            Select
            Case GUICtrlRead($PathtoPatchInput) = ""
                $Message1 = $Message1 & "You have not entered or selected a command." & @LF
                GUICtrlSetData($Status1, $Message1)
            Case StringRight(GUICtrlRead($PathtoPatchInput), 1) = "\"
                $Message1 = $Message1 & "You have not entered a valid command in the path box." & @LF
                GUICtrlSetData($Status1, $Message1)
            Case Not FileExists(GUICtrlRead($PathtoPatchInput))
                $Message1 = $Message1 & "The command you entered does not exist at that location." & @LF
                GUICtrlSetData($Status1, $Message1)
            Case Else
                $StubCommand = GUICtrlRead($PathtoPatchInput) & " " & GUICtrlRead($CommandParametersInput)
                $Message1 = $Message1 & "Command constructed successfully.  " & @LF
                GUICtrlSetData($Status1, $Message1)
                _ExecuteFunction()
        EndSelect
    EndSelect
    
EndFunc


;============================================
; _ExecuteFunction                          |
;============================================

Func _ExecuteFunction()
    
    Dim $SrvStub[500]
    
    Select
    Case GUICtrlRead($NativeCheckedInput) = $GUI_UNCHECKED
        $PSEXEC = "C:\Windows\psexec.exe -c "
    Case GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED
        $PSEXEC = "C:\Windows\psexec.exe "
    EndSelect
    
    For $X = 1 to $Temp_Index[0]
        $SrvStub[$X] = $PSEXEC & "\\" & $Selected[$X]
        $FullCommand[$X] = $SrvStub[$X] & " " & $StubCommand
        $Message1 = $Message1 & "Fullcommand: " & $FullCommand[$X] & @LF
        GUICtrlSetData($Status1, $Message1)
    Next
    
    For $X = 1 to $Temp_Index[0]
        $Message1 = $Message1 & "Connecting to the IPC$ share for authentication on server " & $Selected[$X] & "." & @LF
        GUICtrlSetData($Status1, $Message1)
        $Val1 = Run(@ComSpec & " /c " & "Net use /user:" & GUICtrlRead($DomainInput) & "\" & GUICtrlRead($UserIDInput) & " \\" & $Selected[$X] & "\IPC$ " & GUICtrlRead($PasswordInput), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        $Val2 = Run(@ComSpec & " /c " & $FullCommand[$X], @SYSTEMDIR, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        $Message1 = $Message1 & "Command executing on " & $Selected[$X] & ": " & $StubCommand & @LF
        GUICtrlSetData($Status1, $Message1)
        $Message1 = $Message1 & StdoutRead($Val2) & @LF
        GUICtrlSetData($Status1, $Message1)
    Next
    
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

HI,

not very smart, but maybe it is good enough :">

Topic 1)

;============================================
; Includes                            |
;============================================

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <constants.au3>
#include <File.au3>

;============================================
; Declarations                                |
;============================================

Global $PathtoPatch, $PathtoPatchInput, $NativeCheckedInput
Global $Status1, $Status2
Global $Message1 = "Server status messages will appear here." & Chr(10)
Dim $ServerArray[500], $ListItem[500], $Selected[500], $Temp_Index, $FullCommand[500]
Global $CaclsInput, $CmdWindowInput, $CommandParametersInput, $NativeCommand, $StubCommand
Global $UserIDInput, $PasswordInput, $DomainInput, $check = 0

;============================================
; Main                                        |
;============================================

Opt("RunErrorsFatal", 0)
_FileCreate("C:\ServerList.txt")
If FileExists("C:\ServerList.txt") Then
    _GUISetup()
Else
    MsgBox(16, "Error!", "You need a server list!")
EndIf
;=========================================================================================
; NOTE:  At the moment this program expects to find a text file listing of the servers   |
; it needs for one of the tabs in C:\.  I will get around to making it more dynamic         |
; later on, perhaps a search of your domain when I figure out how to do that.  For now,     |
; you can just make up some names and make a list.                                         |
;=========================================================================================

;============================================
; _GUISetup                                    |
;============================================

Func _GUISetup()
    
    $PathtoPatch = "C:\Patches\"
    Local $LineCounter = 1
    Local $listview, $Pressed
    
    $ServerList = FileOpen("C:\ServerList.txt", 0)
    While 1
        $Line = FileReadLine($ServerList)
        If @error = -1 Then ExitLoop
        $ServerArray[$LineCounter] = $Line
        $LineCounter = $LineCounter + 1
    WEnd
    
    GUICreate("Patch Panel", 900, 500)
    
    $Submit = GUICtrlCreateButton("Submit", 150, 470, 50, 20)
    $Exit = GUICtrlCreateButton("Exit", 225, 470, 50, 20)
    $Clear = GUICtrlCreateButton("Clear", 300, 470, 50, 20)
    $Status1 = GUICtrlCreateEdit($Message1, 500, 24, 400, 470, BitOR($ES_READONLY, $ES_LEFT, $ES_AUTOVSCROLL, $WS_VSCROLL, $ES_MULTILINE, $WS_HSCROLL))
    
    GUICtrlCreateTab(2, 2, 498, 460)
    
    $PatchTab = GUICtrlCreateTabItem("Patches")
    $PathtoPatchLabel = GUICtrlCreateLabel("Path to Executable: ", 10, 30, 125, 18)
    $PathtoPatchInput = GUICtrlCreateInput($PathtoPatch, 130, 30, 100, 18)
    
    $NativeCheckedInput = GUICtrlCreateCheckbox("Use a Native Command (Below)", 130, 55)
    
    $CommandParametersLabel = GUICtrlCreateLabel("Command Parameters:", 10, 80, 125, 18)
    $CommandParametersInput = GUICtrlCreateInput("", 130, 80, 200, 18)
    
    $UserIDLabel = GUICtrlCreateLabel("User ID:", 10, 105, 125, 18)
    $UserIDInput = GUICtrlCreateInput(@UserName, 130, 105, 200, 18)
    
    $PasswordLabel = GUICtrlCreateLabel("Password:", 10, 130, 125, 18)
    $PasswordInput = GUICtrlCreateInput("", 130, 130, 200, 18, $ES_PASSWORD)
    
    $DomainLabel = GUICtrlCreateLabel("Domain/Server:", 10, 155, 125, 18)
    $DomainInput = GUICtrlCreateInput(@LogonDomain, 130, 155, 200, 18)
    
    GUICtrlCreateGroup("Native Commands", 10, 190, 480, 260)
    $CaclsInput = GUICtrlCreateRadio("CACLS", 15, 215)
    ;$CmdWindowInput = GUICtrlCreateRadio("DOS Window", 15, 240)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    
    $ServerTab = GUICtrlCreateTabItem("Servers")
    
    $listview = GUICtrlCreateListView("Server List", 10, 60, 400, 200, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
    For $X = 1 To $LineCounter - 1
        $ListItem[$X] = GUICtrlCreateListViewItem($ServerArray[$X], $listview)
    Next
    
    GUISetState()
    
    While 1
        $Pressed = GUIGetMsg()
        Select
            Case $Pressed = $Submit
                $Temp_Index = _GUICtrlListViewGetSelectedIndices($listview, 1)
                If IsArray($Temp_Index) Then
                    GUICtrlSetData($Status1, "OK")
                    For $X = 1 To $Temp_Index[0]
                        $Selected[$X] = _GUICtrlListViewGetItemText($listview, $Temp_Index[$X])
                        _VerifyFunction()
                    Next
                Else
                    $Message1 = $Message1 & "No servers selected.  You must select one from the server list." & @LF
                    GUICtrlSetData($Status1, $Message1)
                EndIf
            Case $Pressed = $GUI_EVENT_CLOSE
                ExitLoop
            Case $Pressed = $Exit
                ExitLoop
            Case $Pressed = $Clear
                $Message1 = ""
                GUICtrlSetData($Status1, $Message1)
        EndSelect
        If $check = 50 Then 
        If GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED Then
            GUICtrlSetState($PathtoPatchInput, $GUI_DISABLE)
        Else
            GUICtrlSetState($PathtoPatchInput, $GUI_ENABLE)
        EndIf
        $check = 0
    EndIf
    $check+=1
    WEnd
EndFunc   ;==>_GUISetup


;============================================
; _VerifyFunction                            |
;============================================

Func _VerifyFunction()
    
    Select
        Case GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED
            Select
                Case GUICtrlRead($CaclsInput) = $GUI_CHECKED
                    $StubCommand = "cacls " & GUICtrlRead($CommandParametersInput)
                    $Message1 = $Message1 & "Command constructed successfully.  " & @LF
                    GUICtrlSetData($Status1, $Message1)
                    _ExecuteFunction()
                    ;Case GUICtrlRead($CmdWindowInput) = $GUI_CHECKED
                    ;    $StubCommand = "cmd " & GUICtrlRead($CommandParametersInput)
                    ;    $Message1 = $Message1 & "Command contructed successfully." & @LF
                    ;    _ExecuteFunction()
                Case Else
                    $Message1 = $Message1 & "You need to select a native command or clear the checkbox and type one in." & @LF
                    GUICtrlSetData($Status1, $Message1)
            EndSelect
        Case GUICtrlRead($NativeCheckedInput) = $GUI_UNCHECKED
            Select
                Case GUICtrlRead($PathtoPatchInput) = ""
                    $Message1 = $Message1 & "You have not entered or selected a command." & @LF
                    GUICtrlSetData($Status1, $Message1)
                Case StringRight(GUICtrlRead($PathtoPatchInput), 1) = "\"
                    $Message1 = $Message1 & "You have not entered a valid command in the path box." & @LF
                    GUICtrlSetData($Status1, $Message1)
                Case Not FileExists(GUICtrlRead($PathtoPatchInput))
                    $Message1 = $Message1 & "The command you entered does not exist at that location." & @LF
                    GUICtrlSetData($Status1, $Message1)
                Case Else
                    $StubCommand = GUICtrlRead($PathtoPatchInput) & " " & GUICtrlRead($CommandParametersInput)
                    $Message1 = $Message1 & "Command constructed successfully.  " & @LF
                    GUICtrlSetData($Status1, $Message1)
                    _ExecuteFunction()
            EndSelect
    EndSelect
    
EndFunc   ;==>_VerifyFunction


;============================================
; _ExecuteFunction                            |
;============================================

Func _ExecuteFunction()
    
    Dim $SrvStub[500]
    
    Select
        Case GUICtrlRead($NativeCheckedInput) = $GUI_UNCHECKED
            $PSEXEC = "C:\Windows\psexec.exe -c "
        Case GUICtrlRead($NativeCheckedInput) = $GUI_CHECKED
            $PSEXEC = "C:\Windows\psexec.exe "
    EndSelect
    
    For $X = 1 To $Temp_Index[0]
        $SrvStub[$X] = $PSEXEC & "\\" & $Selected[$X]
        $FullCommand[$X] = $SrvStub[$X] & " " & $StubCommand
        $Message1 = $Message1 & "Fullcommand: " & $FullCommand[$X] & @LF
        GUICtrlSetData($Status1, $Message1)
    Next
    
    For $X = 1 To $Temp_Index[0]
        $Message1 = $Message1 & "Connecting to the IPC$ share for authentication on server " & $Selected[$X] & "." & @LF
        GUICtrlSetData($Status1, $Message1)
        $Val1 = Run(@ComSpec & " /c " & "Net use /user:" & GUICtrlRead($DomainInput) & "\" & GUICtrlRead($UserIDInput) & " \\" & $Selected[$X] & "\IPC$ " & GUICtrlRead($PasswordInput), @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        $Val2 = Run(@ComSpec & " /c " & $FullCommand[$X], @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
        $Message1 = $Message1 & "Command executing on " & $Selected[$X] & ": " & $StubCommand & @LF
        GUICtrlSetData($Status1, $Message1)
        $Message1 = $Message1 & StdoutRead($Val2) & @LF
        GUICtrlSetData($Status1, $Message1)
    Next
    
EndFunc   ;==>_ExecuteFunction
FileDelete("C:\ServerList.txt")

So long,

Mega

Edited by th.meger

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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
Sign in to follow this  
Followers 0