Jump to content
Sign in to follow this  
Stunt

Selecting an Item on existing a list box

Recommended Posts

Stunt

Hi All,

I have a script which creates a listbox, I am trying to automate selecting an item of that list box. But cant seen to get focus on it or controlsend to it, or maybe thats not the way to do it. Have had a look at some of the _GUI commands but they loose me. Can anyone help PLEEEEASE?

Here is the script that creates the listbox:

#Region Compiler directives section

;** This is a list of compiler directives used by CompileAU3.exe.

;** comment the lines you don't need or else it will override the default settings

;#Compiler_Prompt=y ;y=show compile menu

;** AUT2EXE settings

;#Compiler_AUT2EXE=

;#Compiler_Icon=Wizard.ico ;Filename of the Ico file to use

;#Compiler_OutFile= ;Target exe filename.

#Compiler_Compression=4 ;Compression parameter 0-4 0=Low 2=normal 4=High

#Compiler_Allow_Decompile=y ;y= allow decompile

;#Compiler_PassPhrase= ;Password to use for compilation

;** Target program Resource info

#Compiler_Res_Comment=Unix Shell Management

#Compiler_Res_Description=Unix Shell Management

#Compiler_Res_Fileversion=1.2

#Compiler_Res_LegalCopyright=Giuseppe Criaco

; free form resource fields ... max 15

#Compiler_Res_Field=Email|gcriaco@sogei.it ;Free format fieldname|fieldvalue

#Compiler_Res_Field=Release Date|1/25/2006 ;Free format fieldname|fieldvalue

;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue

;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue

#Compiler_Run_AU3Check=y ;Run au3check before compilation

; The following directives can contain:

; %in% , %out%, %icon% which will be replaced by the fullpath\filename.

; %scriptdir% same as @ScriptDir and %scriptfile% = filename without extension.

#Compiler_Run_Before= ;process to run before compilation - you can have multiple records that will be processed in sequence

#Compiler_Run_After=move "%out%" "%scriptdir%" ;process to run After compilation - you can have multiple records that will be processed in sequence

#EndRegion

;===================================================================================================

================================================

;

; Program Name: UnixCmd()

; Description: Unix Shell Management

; Parameter(s): None

; Requirement(s): UnixCmd.ini, PuTTY Executable

; Return Value(s): None

; Author(s): Giuseppe Criaco <gcriaco@quipo.it>

;

;===================================================================================================

================================================

;

#Region - Include and Declarations

AutoItSetOption("TrayIconDebug", 1) ;Debug: 0=no info, 1=debug line info

#include <string.au3>

#include <GuiConstants.au3>

Global Const $WM_COMMAND = 0x0111

Global Const $LBN_SELCHANGE = 1

Global Const $LBN_DBLCLK = 2

Dim $asCmd[50], $iCmd = 0, $ip, $sHostName, $sEncryptPwd, $sPwd, $sUser, $iSleep = 1000, $sPutty, $iSendKeyDelay = 50

#EndRegion - Include and Declarations

#Region - GUI objects creation

GuiCreate("UnixCmd v. 1.2", 235, 375,(@DesktopWidth-325)/2, (@DesktopHeight-285)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Server List:", 10, 10, 135, 30)

$lstServer = GuiCtrlCreateList("", 10, 30, 215, 310)

$btnOk = GuiCtrlCreateButton("&Start", 75, 340, 70, 25, $BS_DEFPUSHBUTTON )

$btnExit = GuiCtrlCreateButton("&Exit", 155, 340, 70, 25)

HotKeySet("{ESC}", "_Terminate")

#EndRegion - GUI objects creation

#Region Management

If (Not FileExists(@ScriptDir & "\UnixCmd.ini")) Then

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning

MsgBox(48, "File Not Found", "Required file not found (" & @ScriptDir & "\UnixCmd.ini" & ")" & @CRLF & "" & @CRLF & "UnixCmd will now exit!!!")

#EndRegion --- CodeWizard generated code End ---

Exit

EndIf

;General Options

$sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", "General")

If @error Then

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical

MsgBox(16,"UnixCmd","Unable to read the section General")

#EndRegion --- CodeWizard generated code End ---

Exit

Else

;Read Loop on the Section

For $iSection = 1 To $sSection[0][0]

Select

Case $sSection[$iSection][0] = "Putty"

$sPutty = $sSection[$iSection][1]

EndSelect

Next

EndIf

$var = IniReadSectionNames(@ScriptDir & "\UnixCmd.ini")

If @error Then

MsgBox(4096, "", "Error occured, probably no INI file.")

Else

;Load ListBox

For $i = 1 To $var[0]

if $var[$i] <> "General" Then GUICtrlSetData($lstServer,$var[$i])

Next

EndIf

; create the symmetric decryption key

$sSymmetricKey = _StringToHex ("wef,5RDx")

;Register a user defined function for the Windows Message ID WM_COMMAND.

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GuiSetState()

While 1

$msg = GuiGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE Or $msg = $btnExit

_Terminate()

Case $msg = $btnOk

_Start()

EndSelect

WEnd

;===============================================================================

; Function Name: _StartPuTTY($sIP)

; Description: Start a Telnet session by PuTTY

; Parameter(s): None

; Requirement(s): None

; Return Value(s): None

; Author(s): Giuseppe Criaco <gcriaco@quipo.it>

;===============================================================================

Func _StartPuTTY($sIP)

Run(Chr(34) & $sPutty & Chr(34) & " -load " & Chr(34) & $sHostName & Chr(34))

WinWait($sIP & " - PuTTY", "")

If Not WinActive($sIP & " - PuTTY","") Then WinActivate($sIP & " - PuTTY","")

WinWaitActive($sIP & " - PuTTY","")

Sleep($iSleep)

EndFunc ;==>_StartPuTTY

Func _Terminate()

Exit 0

EndFunc

;===============================================================================

; Function Name: _Start()

; Description: None

; Parameter(s): None

; Requirement(s): None

; Return Value(s): None

; Author(s): Giuseppe Criaco <gcriaco@quipo.it>

;===============================================================================

Func _Start()

$sHostName = GUICtrlRead($lstServer)

$sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", $sHostName)

If @error Then

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical

MsgBox(16,"UnixCmd","Unable to read the section " & $sHostName)

#EndRegion --- CodeWizard generated code End ---

Exit

Else

;Read Loop on the Section

For $iSection = 1 To $sSection[0][0]

Select

Case $sSection[$iSection][0] = "IP"

$sIP = $sSection[$iSection][1]

Case $sSection[$iSection][0] = "User"

$sUser = $sSection[$iSection][1]

Case $sSection[$iSection][0] = "Pwd"

$sEncryptPwd = $sSection[$iSection][1]

;Decrypt user password

$sPwd = _StringEncrypt(0,$sEncryptPwd,_StringToHex ("wef,5RDx"))

If @error = 1 Then

#Region --- CodeWizard generated code Start ---

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical

MsgBox(16,"UnixCmd","_StringEncrypt of " & $sEncryptPwd & " Failed")

#EndRegion --- CodeWizard generated code End ---

Exit

EndIf

Case $sSection[$iSection][0] = "SendKeyDelay"

$iSendKeyDelay = $sSection[$iSection][1]

Case $sSection[$iSection][0] = "Sleep"

$iSleep = $sSection[$iSection][1]

Case Else

If StringLeft ($sSection[$iSection][0], 1) <> "#" Then

$sCmdTmp = $sSection[$iSection][1]

If StringIsXDigit($sCmdTmp) Then ;returns 1

;Decrypt Item

$asCmd[$iCmd] = _StringEncrypt(0,$sCmdTmp,_StringToHex ("wef,5RDx"))

If @error = 1 Then

;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical

MsgBox(16,"UnixCmd","_StringEncrypt of " & $sCmdTmp & " Failed")

Exit

EndIf

Else

$asCmd[$iCmd] = $sCmdTmp

EndIf

$iCmd = $iCmd + 1

EndIf

EndSelect

Next

BlockInput(1)

;Start a PuTTY Telnet/SSH Session

_StartPuTTY($sIP)

AutoItSetOption("SendKeyDelay", $iSendKeyDelay)

;Login to the server

ControlSend ($sIP & " - PuTTY", "", "", $sUser & "{ENTER}")

ControlSend ($sIP & " - PuTTY", "", "", $sPwd & "{ENTER}")

; Executes commands listed under the INI Section

If $iCmd > 0 Then

$iTotItems = $iCmd -1

$iCmd = 0

For $iCmd = 0 To $iTotItems

ControlSend ($sIP & " - PuTTY", "", "", $asCmd[$iCmd] & "{ENTER}")

Next

EndIf

BlockInput(0)

EndIf

_Terminate()

EndFunc

;===============================================================================

; Function Name: MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

; Description: None

; Parameter(s): None

; Requirement(s): None

; Return Value(s): None

; Author(s): Holger

;===============================================================================

Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)

$nNotifyCode = BitShift($wParam, 16)

$nID = BitAnd($wParam, 0x0000FFFF)

$hCtrl = $lParam

If $nID = $lstServer Then

Switch $nNotifyCode

Case $LBN_DBLCLK

_Start()

Return 0

EndSwitch

EndIf

EndFunc

Thanks,

Stuntman

Share this post


Link to post
Share on other sites
GaryFrost

1st please put code in between [ autoit][ /autoit] without the spaces

2nd provide an ini.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Stunt

1st please put code in between [ autoit][ /autoit] without the spaces

2nd provide an ini.

File Attached. Sorry didnt know about the [ autoit][ /autoit], looking at it some more, even if we could get the script to autoselect my server in the ini file and run it without and interation from me would be best - but im still quite new and this is a bit over my head...

Thanks for coming back to me.

Stunt

Cant seem to upload files, it is below. My file name is UnixCmd.ini:

[General]

Putty=C:\AutoDeploy\putty.exe

[szaordv1]

IP=10.56.154.10

User=jde

Pwd=D1501DA3A043DDFF5FC7C3EC1DE108003FA2

sleep=3000

SendKeyDelay=100

Cmd1=rm -R /u03/jdedwardsoneworld/b7334/packages/AUTODEPLOY{ENTER}

Cmd2=exit{ENTER}

Share this post


Link to post
Share on other sites
GaryFrost

I'm guessing you mean something like:

#Region Compiler directives section
;** This is a list of compiler directives used by CompileAU3.exe.
;** comment the lines you don't need or else it will override the default settings
;#Compiler_Prompt=y ;y=show compile menu
;** AUT2EXE settings
;#Compiler_AUT2EXE=
;#Compiler_Icon=Wizard.ico ;Filename of the Ico file to use
;#Compiler_OutFile= ;Target exe filename.
#Compiler_Compression=4 ;Compression parameter 0-4 0=Low 2=normal 4=High
#Compiler_Allow_Decompile=y ;y= allow decompile
;#Compiler_PassPhrase= ;Password to use for compilation
;** Target program Resource info
#Compiler_Res_Comment=Unix Shell Management
#Compiler_Res_Description=Unix Shell Management
#Compiler_Res_Fileversion=1.2
#Compiler_Res_LegalCopyright=Giuseppe Criaco
; free form resource fields ... max 15
#Compiler_Res_Field=Email|gcriaco@sogei.it ;Free format fieldname|fieldvalue
#Compiler_Res_Field=Release Date|1/25/2006 ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue
#Compiler_Run_AU3Check=y ;Run au3check before compilation
; The following directives can contain:
; %in% , %out%, %icon% which will be replaced by the fullpath\filename.
; %scriptdir% same as @ScriptDir and %scriptfile% = filename without extension.
#Compiler_Run_Before= ;process to run before compilation - you can have multiple records that will be processed in sequence
#Compiler_Run_After=move "%out%" "%scriptdir%" ;process to run After compilation - you can have multiple records that will be processed in sequence
#EndRegion
;===================================================================================================
;== == == == == == == == == == == == == == == == == == == == == == == == 
;
; Program Name: UnixCmd()
; Description: Unix Shell Management
; Parameter(s): None
; Requirement(s): UnixCmd.ini, PuTTY Executable
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;
;===================================================================================================
;== == == == == == == == == == == == == == == == == == == == == == == == 
;

#Region - Include and Declarations

AutoItSetOption("TrayIconDebug", 1) ;Debug: 0=no info, 1=debug line info

#include <string.au3>
#include <GuiConstants.au3>
#include <GuiList.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $LBN_SELCHANGE = 1
Global Const $LBN_DBLCLK = 2

Dim $asCmd[50], $iCmd = 0, $ip, $sHostName, $sEncryptPwd, $sPwd, $sUser, $iSleep = 1000, $sPutty, $iSendKeyDelay = 50

#EndRegion - Include and Declarations

#Region - GUI objects creation

GUICreate("UnixCmd v. 1.2", 235, 375, (@DesktopWidth - 325) / 2, (@DesktopHeight - 285) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Server List:", 10, 10, 135, 30)
$lstServer = GUICtrlCreateList("", 10, 30, 215, 310)
$btnOk = GUICtrlCreateButton("&Start", 75, 340, 70, 25, $BS_DEFPUSHBUTTON)
$btnExit = GUICtrlCreateButton("&Exit", 155, 340, 70, 25)

HotKeySet("{ESC}", "_Terminate")

#EndRegion - GUI objects creation

#Region Management

If (Not FileExists(@ScriptDir & "\UnixCmd.ini")) Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning
    MsgBox(48, "File Not Found", "Required file not found (" & @ScriptDir & "\UnixCmd.ini" & ")" & @CRLF & "" & @CRLF & "UnixCmd will now exit!!!")
    #EndRegion --- CodeWizard generated code End ---
    Exit
EndIf

;General Options
$sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", "General")
If @error Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16, "UnixCmd", "Unable to read the section General")
    #EndRegion --- CodeWizard generated code End ---
    Exit
Else
    ;Read Loop on the Section
    For $iSection = 1 To $sSection[0][0]
        Select
            Case $sSection[$iSection][0] = "Putty"
                $sPutty = $sSection[$iSection][1]

        EndSelect
    Next
EndIf

$var = IniReadSectionNames(@ScriptDir & "\UnixCmd.ini")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    ;Load ListBox
    For $i = 1 To $var[0]
        If $var[$i] <> "General" Then GUICtrlSetData($lstServer, $var[$i])
    Next
EndIf

; create the symmetric decryption key
$sSymmetricKey = _StringToHex("wef,5RDx")

;Register a user defined function for the Windows Message ID WM_COMMAND.
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState()
If _GUICtrlListCount($lstServer) > 0 Then 
    _GUICtrlListSelectIndex($lstServer, 0)
    _Start()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $btnExit
            _Terminate()

        Case $msg = $btnOk
            _Start()
    EndSelect
WEnd

;===============================================================================
; Function Name: _StartPuTTY($sIP)
; Description: Start a Telnet session by PuTTY
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;===============================================================================

Func _StartPuTTY($sIP)
    Run(Chr(34) & $sPutty & Chr(34) & " -load " & Chr(34) & $sHostName & Chr(34))
    WinWait($sIP & " - PuTTY", "")
    If Not WinActive($sIP & " - PuTTY", "") Then WinActivate($sIP & " - PuTTY", "")
    WinWaitActive($sIP & " - PuTTY", "")
    Sleep($iSleep)
EndFunc   ;==>_StartPuTTY

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

;===============================================================================
; Function Name: _Start()
; Description: None
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;===============================================================================

Func _Start()
    $sHostName = GUICtrlRead($lstServer)
    $sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", $sHostName)
    If @error Then
        #Region --- CodeWizard generated code Start ---
        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
        MsgBox(16, "UnixCmd", "Unable to read the section " & $sHostName)
        #EndRegion --- CodeWizard generated code End ---
        Exit
    Else
        ;Read Loop on the Section
        For $iSection = 1 To $sSection[0][0]
            Select
                Case $sSection[$iSection][0] = "IP"
                    $sIP = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "User"
                    $sUser = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "Pwd"
                    $sEncryptPwd = $sSection[$iSection][1]
                    ;Decrypt user password
                    $sPwd = _StringEncrypt(0, $sEncryptPwd, _StringToHex("wef,5RDx"))
                    If @error = 1 Then
                        #Region --- CodeWizard generated code Start ---
                        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
                        MsgBox(16, "UnixCmd", "_StringEncrypt of " & $sEncryptPwd & " Failed")
                        #EndRegion --- CodeWizard generated code End ---
                        Exit
                    EndIf

                Case $sSection[$iSection][0] = "SendKeyDelay"
                    $iSendKeyDelay = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "Sleep"
                    $iSleep = $sSection[$iSection][1]

                Case Else
                    If StringLeft($sSection[$iSection][0], 1) <> "#" Then
                        $sCmdTmp = $sSection[$iSection][1]
                        If StringIsXDigit($sCmdTmp) Then ;returns 1
                            ;Decrypt Item
                            $asCmd[$iCmd] = _StringEncrypt(0, $sCmdTmp, _StringToHex("wef,5RDx"))
                            If @error = 1 Then
                                ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
                                MsgBox(16, "UnixCmd", "_StringEncrypt of " & $sCmdTmp & " Failed")
                                Exit
                            EndIf
                        Else
                            $asCmd[$iCmd] = $sCmdTmp
                        EndIf

                        $iCmd = $iCmd + 1
                    EndIf
            EndSelect
        Next

        BlockInput(1)

        ;Start a PuTTY Telnet/SSH Session
        _StartPuTTY($sIP)

        AutoItSetOption("SendKeyDelay", $iSendKeyDelay)

        ;Login to the server
        ControlSend($sIP & " - PuTTY", "", "", $sUser & "{ENTER}")
        ControlSend($sIP & " - PuTTY", "", "", $sPwd & "{ENTER}")

        ; Executes commands listed under the INI Section
        If $iCmd > 0 Then
            $iTotItems = $iCmd - 1
            $iCmd = 0

            For $iCmd = 0 To $iTotItems
                ControlSend($sIP & " - PuTTY", "", "", $asCmd[$iCmd] & "{ENTER}")
            Next
        EndIf

        BlockInput(0)

    EndIf

    _Terminate()
EndFunc   ;==>_Start

;===============================================================================
; Function Name: MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
; Description: None
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Holger
;===============================================================================

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    If $nID = $lstServer Then
        Switch $nNotifyCode
            Case $LBN_DBLCLK
                _Start()
                Return 0
        EndSwitch
    EndIf
EndFunc   ;==>MY_WM_COMMAND

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Stunt

I'm guessing you mean something like:

#Region Compiler directives section
;** This is a list of compiler directives used by CompileAU3.exe.
;** comment the lines you don't need or else it will override the default settings
;#Compiler_Prompt=y ;y=show compile menu
;** AUT2EXE settings
;#Compiler_AUT2EXE=
;#Compiler_Icon=Wizard.ico ;Filename of the Ico file to use
;#Compiler_OutFile= ;Target exe filename.
#Compiler_Compression=4 ;Compression parameter 0-4 0=Low 2=normal 4=High
#Compiler_Allow_Decompile=y ;y= allow decompile
;#Compiler_PassPhrase= ;Password to use for compilation
;** Target program Resource info
#Compiler_Res_Comment=Unix Shell Management
#Compiler_Res_Description=Unix Shell Management
#Compiler_Res_Fileversion=1.2
#Compiler_Res_LegalCopyright=Giuseppe Criaco
; free form resource fields ... max 15
#Compiler_Res_Field=Email|gcriaco@sogei.it ;Free format fieldname|fieldvalue
#Compiler_Res_Field=Release Date|1/25/2006 ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue
;#Compiler_Res_Field=Name|Value ;Free format fieldname|fieldvalue
#Compiler_Run_AU3Check=y ;Run au3check before compilation
; The following directives can contain:
; %in% , %out%, %icon% which will be replaced by the fullpath\filename.
; %scriptdir% same as @ScriptDir and %scriptfile% = filename without extension.
#Compiler_Run_Before= ;process to run before compilation - you can have multiple records that will be processed in sequence
#Compiler_Run_After=move "%out%" "%scriptdir%" ;process to run After compilation - you can have multiple records that will be processed in sequence
#EndRegion
;===================================================================================================
;== == == == == == == == == == == == == == == == == == == == == == == == 
;
; Program Name: UnixCmd()
; Description: Unix Shell Management
; Parameter(s): None
; Requirement(s): UnixCmd.ini, PuTTY Executable
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;
;===================================================================================================
;== == == == == == == == == == == == == == == == == == == == == == == == 
;

#Region - Include and Declarations

AutoItSetOption("TrayIconDebug", 1) ;Debug: 0=no info, 1=debug line info

#include <string.au3>
#include <GuiConstants.au3>
#include <GuiList.au3>

Global Const $WM_COMMAND = 0x0111
Global Const $LBN_SELCHANGE = 1
Global Const $LBN_DBLCLK = 2

Dim $asCmd[50], $iCmd = 0, $ip, $sHostName, $sEncryptPwd, $sPwd, $sUser, $iSleep = 1000, $sPutty, $iSendKeyDelay = 50

#EndRegion - Include and Declarations

#Region - GUI objects creation

GUICreate("UnixCmd v. 1.2", 235, 375, (@DesktopWidth - 325) / 2, (@DesktopHeight - 285) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

GUICtrlCreateLabel("Server List:", 10, 10, 135, 30)
$lstServer = GUICtrlCreateList("", 10, 30, 215, 310)
$btnOk = GUICtrlCreateButton("&Start", 75, 340, 70, 25, $BS_DEFPUSHBUTTON)
$btnExit = GUICtrlCreateButton("&Exit", 155, 340, 70, 25)

HotKeySet("{ESC}", "_Terminate")

#EndRegion - GUI objects creation

#Region Management

If (Not FileExists(@ScriptDir & "\UnixCmd.ini")) Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning
    MsgBox(48, "File Not Found", "Required file not found (" & @ScriptDir & "\UnixCmd.ini" & ")" & @CRLF & "" & @CRLF & "UnixCmd will now exit!!!")
    #EndRegion --- CodeWizard generated code End ---
    Exit
EndIf

;General Options
$sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", "General")
If @error Then
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
    MsgBox(16, "UnixCmd", "Unable to read the section General")
    #EndRegion --- CodeWizard generated code End ---
    Exit
Else
    ;Read Loop on the Section
    For $iSection = 1 To $sSection[0][0]
        Select
            Case $sSection[$iSection][0] = "Putty"
                $sPutty = $sSection[$iSection][1]

        EndSelect
    Next
EndIf

$var = IniReadSectionNames(@ScriptDir & "\UnixCmd.ini")
If @error Then
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    ;Load ListBox
    For $i = 1 To $var[0]
        If $var[$i] <> "General" Then GUICtrlSetData($lstServer, $var[$i])
    Next
EndIf

; create the symmetric decryption key
$sSymmetricKey = _StringToHex("wef,5RDx")

;Register a user defined function for the Windows Message ID WM_COMMAND.
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState()
If _GUICtrlListCount($lstServer) > 0 Then 
    _GUICtrlListSelectIndex($lstServer, 0)
    _Start()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $btnExit
            _Terminate()

        Case $msg = $btnOk
            _Start()
    EndSelect
WEnd

;===============================================================================
; Function Name: _StartPuTTY($sIP)
; Description: Start a Telnet session by PuTTY
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;===============================================================================

Func _StartPuTTY($sIP)
    Run(Chr(34) & $sPutty & Chr(34) & " -load " & Chr(34) & $sHostName & Chr(34))
    WinWait($sIP & " - PuTTY", "")
    If Not WinActive($sIP & " - PuTTY", "") Then WinActivate($sIP & " - PuTTY", "")
    WinWaitActive($sIP & " - PuTTY", "")
    Sleep($iSleep)
EndFunc   ;==>_StartPuTTY

Func _Terminate()
    Exit 0
EndFunc   ;==>_Terminate

;===============================================================================
; Function Name: _Start()
; Description: None
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Giuseppe Criaco <gcriaco@quipo.it>
;===============================================================================

Func _Start()
    $sHostName = GUICtrlRead($lstServer)
    $sSection = IniReadSection(@ScriptDir & "\UnixCmd.ini", $sHostName)
    If @error Then
        #Region --- CodeWizard generated code Start ---
        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
        MsgBox(16, "UnixCmd", "Unable to read the section " & $sHostName)
        #EndRegion --- CodeWizard generated code End ---
        Exit
    Else
        ;Read Loop on the Section
        For $iSection = 1 To $sSection[0][0]
            Select
                Case $sSection[$iSection][0] = "IP"
                    $sIP = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "User"
                    $sUser = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "Pwd"
                    $sEncryptPwd = $sSection[$iSection][1]
                    ;Decrypt user password
                    $sPwd = _StringEncrypt(0, $sEncryptPwd, _StringToHex("wef,5RDx"))
                    If @error = 1 Then
                        #Region --- CodeWizard generated code Start ---
                        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
                        MsgBox(16, "UnixCmd", "_StringEncrypt of " & $sEncryptPwd & " Failed")
                        #EndRegion --- CodeWizard generated code End ---
                        Exit
                    EndIf

                Case $sSection[$iSection][0] = "SendKeyDelay"
                    $iSendKeyDelay = $sSection[$iSection][1]

                Case $sSection[$iSection][0] = "Sleep"
                    $iSleep = $sSection[$iSection][1]

                Case Else
                    If StringLeft($sSection[$iSection][0], 1) <> "#" Then
                        $sCmdTmp = $sSection[$iSection][1]
                        If StringIsXDigit($sCmdTmp) Then ;returns 1
                            ;Decrypt Item
                            $asCmd[$iCmd] = _StringEncrypt(0, $sCmdTmp, _StringToHex("wef,5RDx"))
                            If @error = 1 Then
                                ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
                                MsgBox(16, "UnixCmd", "_StringEncrypt of " & $sCmdTmp & " Failed")
                                Exit
                            EndIf
                        Else
                            $asCmd[$iCmd] = $sCmdTmp
                        EndIf

                        $iCmd = $iCmd + 1
                    EndIf
            EndSelect
        Next

        BlockInput(1)

        ;Start a PuTTY Telnet/SSH Session
        _StartPuTTY($sIP)

        AutoItSetOption("SendKeyDelay", $iSendKeyDelay)

        ;Login to the server
        ControlSend($sIP & " - PuTTY", "", "", $sUser & "{ENTER}")
        ControlSend($sIP & " - PuTTY", "", "", $sPwd & "{ENTER}")

        ; Executes commands listed under the INI Section
        If $iCmd > 0 Then
            $iTotItems = $iCmd - 1
            $iCmd = 0

            For $iCmd = 0 To $iTotItems
                ControlSend($sIP & " - PuTTY", "", "", $asCmd[$iCmd] & "{ENTER}")
            Next
        EndIf

        BlockInput(0)

    EndIf

    _Terminate()
EndFunc   ;==>_Start

;===============================================================================
; Function Name: MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
; Description: None
; Parameter(s): None
; Requirement(s): None
; Return Value(s): None
; Author(s): Holger
;===============================================================================

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    $hCtrl = $lParam

    If $nID = $lstServer Then
        Switch $nNotifyCode
            Case $LBN_DBLCLK
                _Start()
                Return 0
        EndSwitch
    EndIf
EndFunc   ;==>MY_WM_COMMAND
Hi,

I see you removed line 63 from the code?

$btnExit = GuiCtrlCreateButton("&Exit", 155, 340, 70, 25) Im not 100% sure what that line did, but with it removed the progrem does not launch?

Can you explain?

Regards,

Stunt

Share this post


Link to post
Share on other sites
GaryFrost

Hi,

I see you removed line 63 from the code?

$btnExit = GuiCtrlCreateButton("&Exit", 155, 340, 70, 25) Im not 100% sure what that line did, but with it removed the progrem does not launch?

Can you explain?

Regards,

Stunt

Didn't remove the button, ran tidy on the script, apparently it is now line 66

Matter of fact I didn't remove anything, just added the include and

If _GUICtrlListCount($lstServer) > 0 Then 
    _GUICtrlListSelectIndex($lstServer, 0)
    _Start()
EndIf

EndIf is missing from the if statement.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Stunt

Didn't remove the button, ran tidy on the script, apparently it is now line 66

Matter of fact I didn't remove anything, just added the include and

If _GUICtrlListCount($lstServer) > 0 Then 
    _GUICtrlListSelectIndex($lstServer, 0)
    _Start()
EndIf

EndIf is missing from the if statement.

My copy paste didnt work to well, missed some lines... I see your change now and have added the EndIf. Could you maybe explain what the included header and your additional lines do, sorry but this is a bit over my head. I am testing it now.

Regards,

Stunt

Share this post


Link to post
Share on other sites
GaryFrost

My copy paste didnt work to well, missed some lines... I see your change now and have added the EndIf. Could you maybe explain what the included header and your additional lines do, sorry but this is a bit over my head. I am testing it now.

Regards,

Stunt

Each function in the help file should have an explanation of what it does and an example.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Stunt

Each function in the help file should have an explanation of what it does and an example.

Thanks for the help. Will readup in the help file.

Stunt

Share this post


Link to post
Share on other sites
Stunt

Thanks for the help. Will readup in the help file.

Stunt

Hi There,

Script still hangs if I am logged off, I am back to where I started when trying to get the ssh to run while being logged off. Is it actually possible to run Autoit while being logged off, cause it seems to work fine if you logged on but not the other way around?

Share this post


Link to post
Share on other sites
Stunt

Each function in the help file should have an explanation of what it does and an example.

Hi There,

Script still hangs if I am logged off, I am back to where I started when trying to get the ssh to run while being logged off. Is it actually possible to run Autoit while being logged off, cause it seems to work fine if you logged on but not the other way around?

Share this post


Link to post
Share on other sites
GaryFrost

Hi There,

Script still hangs if I am logged off, I am back to where I started when trying to get the ssh to run while being logged off. Is it actually possible to run Autoit while being logged off, cause it seems to work fine if you logged on but not the other way around?

You'll find scripts that require interaction with a GUI require someone to be logged in.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites
Stunt

You'll find scripts that require interaction with a GUI require someone to be logged in.

Ok well then back to my ssh I suppose. I have this script which executes ssh.exe, it runs fine if I am logged in but not if I am logged off and it does not have any GUI interface?

[ autoit];Removes Package Directory from the Enterprise Server

Run("C:\Program Files\OpenSSH\bin\ssh -l jde 10.56.154.10")

WinWait("C:\Program Files\OpenSSH\bin\ssh.exe")

$sshWind = WinGetHandle("C:\Program Files\OpenSSH\bin\ssh.exe")

ControlSend($sshWind, "", "", "1029{ENTER}")

ControlSend($sshWind, "", "", "rm -R /u03/jdedwardsoneworld/b7334/packages/AUTODEPLOY{ENTER}")

ControlSend($sshWind, "", "", "exit{ENTER}")[ /autoit]

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  

×