-
Posts
12 -
Joined
-
Last visited
Everything posted by TexWiller
-
That was it! But I think you already knew ... 😉 I modified the code to also read the STDERR stream. Now i have the full output. So would it generally be better to work with $STDERR_MERGED (same handle for STDOUT and STDERR) for more simplicity or are there special disadvantages? #include <GUIConstantsEx.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> ;Prototype; Proof of concept LogForWebAcc() Func LogForWebAcc() Local $iPID = 0 Local $Vers = "V1.0" ;create GUI Local $hGUI = GUICreate("Login for Web-Access "& $Vers, 800, 900) ;create label Local $hLab0000 = GUICtrlCreateLabel("STDOUT-Stream:", 10, 10, 780, 20) ;create edit Local $hEdi0000 = GUICtrlCreateEdit("", 10, 30, 780, 300) ;create label Local $hLab0001 = GUICtrlCreateLabel("STDERR-Stream:", 10, 340, 780, 20) ;create edit Local $hEdi0001 = GUICtrlCreateEdit("", 10, 360, 780, 300) ;create button Local $hBut0000 = GUICtrlCreateButton("Run plink.exe", 10, 670, 100, 40) ;create label Local $hLab0002 = GUICtrlCreateLabel("Command:", 10, 720, 780, 20) ;create edit Local $hEdi0002 = GUICtrlCreateEdit("", 10, 740, 780, 60) ;create button Local $hBut0001 = GUICtrlCreateButton("Send Command", 10, 810, 100, 40) ;display GUI GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hBut0000 $iPID = Run(@ComSpec & " /c plink.exe -ssh 192.168.30.1 -P 22", @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDIN_CHILD + $STDOUT_CHILD ) Case $hBut0001 StdinWrite($iPID, GUICtrlRead($hEdi0002) & @CRLF) GUICtrlSetData($hEdi0002, "") EndSwitch if $iPID <> 0 Then $Strm = StdoutRead($iPID, True) if GUICtrlRead($hEdi0000) <> $Strm Then GUICtrlSetData($hEdi0000,$Strm) EndIf EndIf if $iPID <> 0 Then $SErr = StderrRead($iPID, True) if GUICtrlRead($hEdi0001) <> $SErr Then GUICtrlSetData($hEdi0001,$SErr) EndIf EndIf WEnd ;delete GUI GUIDelete($hGUI) EndFunc
-
I tested it and added a pause. Unfortunately without any effect. I don't think it's because of the scan rate. - The loop runs (as it is now) with the highest possible frequency (same as the loop of the GUI). - The "true" parameter in "StdoutRead ($iPID, True)" leaves the read data in the stream, but the output is still incomplete. It seems as if part of the output comes into another stream that belongs to the AutoIT script or the SciTE session ... This is what appears in the SciTE console (instead of being intercepted and displayed in control $hEdi0001): If I send "n" then the rest will be read out correctly again. For "username", "password" and 2fa-code it's the same:
-
In a network, some resources can only be accessed if the user has previously logged on to the router. I have to write a small "frontend" program for inexperienced users, which carries out the login via SSH, remains open during the session (connection is alive) and logs off again when it closes. In my test, the SSH call succeeds via "plink.exe" (command-line interface to PuTTY). Also sending the access data succeeds ("n" "(username)" "password" "2fa-code"). However, not the entire output of "plink.exe" is collected. A part ends in SciTE-Console, in which the STDIN stream of the AutoIt script process ends .... What is the best way to avoid this and to intercept the entire output of the "plink.exe" window? Any help is appreciated, thanks. #include <GUIConstantsEx.au3> #include <AutoItConstants.au3> #include <StaticConstants.au3> ;Prototype; Proof of concept LogForWebAcc() Func LogForWebAcc() Local $iPID = 0 Local $Vers = "V1.0" ;create GUI Local $hGUI = GUICreate("Login for Web-Access "& $Vers, 800, 800) ;create edit Local $hEdi0001 = GUICtrlCreateEdit("", 10, 10, 780, 300) ;create button Local $hBut0001 = GUICtrlCreateButton("Run plink.exe", 10, 310, 100, 40) ;create edit Local $hEdi0002 = GUICtrlCreateEdit("", 10, 400, 780, 300) ;create button Local $hBut0002 = GUICtrlCreateButton("Send cmd", 10, 700, 100, 40) ;display GUI GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $hBut0001 $iPID = Run(@ComSpec & " /c plink.exe -ssh 192.168.30.1 -P 22", @ScriptDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD ) ;$STDIO_INHERIT_PARENT ;$RUN_CREATE_NEW_CONSOLE Case $hBut0002 StdinWrite($iPID, GUICtrlRead($hEdi0002) & @CRLF) GUICtrlSetData($hEdi0002, "") EndSwitch if $iPID <> 0 Then $Strm = StdoutRead($iPID, True) if GUICtrlRead($hEdi0001) <> $Strm Then GUICtrlSetData($hEdi0001,$Strm) EndIf EndIf WEnd ;delete GUI GUIDelete($hGUI) EndFunc
-
;========================================================================================================================= ;Get Version from AutoIt3Wrapper directives ;========================================================================================================================= Local $AU3F Local $Line Local $LPos Local $Vers if @Compiled = 0 Then $AU3F = FileReadToArray(@ScriptFullPath) For $LPos = 0 to UBound($AU3F) - 1 $Line = $AU3F[$LPos] if StringInStr($Line,"#AutoIt3Wrapper_Res_ProductVersion=") <> 0 Then $Vers = StringStripWS(StringMid($Line, StringInStr($Line, "=") + 1), $STR_STRIPLEADING + $STR_STRIPTRAILING) ExitLoop EndIf Next EndIf If @Compiled = 1 Then $Vers = FileGetVersion(@ScriptFullPath) EndIf ;=========================================================================================================================
-
First, thank you for your research and for your code sample. I found something else in your code that I was missing in AutoIt so far: $iOrdinal = $iOrdinal = -1 ? 0 : $iOrdinal Probably because I allways searched for a command like: "IIf(Expression, TruePart, FalsePart)" and not for an operator... . Then, to your suggested solution. I read in the AutoIt-Help that some libraries are only accessible by negative values. "... Passing a negative number causes 1-based "index" behaviour. Some Dll can have icon extracted just with negative numbers. ..." So I wanted a solution that would work in any case. "_WinAPI_ExtractIconEx" would do the extraction job, but how to get the icon on the button after extraction? Because "GUICtrlSetImage" seems to be the most direct and recommended way to put pictures on buttons, I hoped there would be a way to use the function with -1 (maybe some kind of flag)... ? What other function would use negative numbers and directly put the icon on a button, and also without using Image lists? I could not find any. Does anyone have a hint?
-
Thank you for the hint. So hier is my sample script: #NoTrayIcon ;============================================================================================================ ;Programm Options ;============================================================================================================ Opt("MustDeclareVars", 1) ;Variables must be pre-declared. Opt("TrayMenuMode", 3) ;The default tray menu items will not be shown, items are not checked when selected. ;============================================================================================================ ;Libraries Inclusions ;============================================================================================================ #include <ColorConstants.au3> #include <TrayConstants.au3> #include <WindowsConstants.au3> #include <FontConstants.au3> #include <GuiConstantsEx.au3> #include <Array.au3> #include <GuiButton.au3> #include <StaticConstants.au3> ;============================================================================================================ ;Global Vars ;============================================================================================================ Global $MainGUIWiHd Global $MGUIGetMsg0 Global $TrayMenMain Global $TrayMenExit Main() Func Main() ;------------------------------------------------------------------------------------------------------------ ;Create Main Window ;------------------------------------------------------------------------------------------------------------ $MainGUIWiHd = GUICreate("Sample", 520, 520, 50, 50, BitOR($WS_SYSMENU, $WS_CAPTION, $DS_SETFOREGROUND)) GUISetFont (8, $FW_NORMAL, $GUI_FONTNORMAL, "Arial", $MainGUIWiHd, $CLEARTYPE_QUALITY) GUISetBkColor(0xDDDDDD, $MainGUIWiHd) GUISetState(@SW_SHOW, $MainGUIWiHd) WinWaitActive($MainGUIWiHd) ;============================================================================================================ ;Create Traymenu ;============================================================================================================ ;Create a Traymenu. $TrayMenMain = TrayCreateItem("Sample", -1, 0) ;Create a Separator line. TrayCreateItem("", -1, -1) ;Create a Menuitem. $TrayMenExit = TrayCreateItem("Exit", -1, -1) ;Show the Traymenu. TraySetState($TRAY_ICONSTATE_SHOW) ;#comments-start ;------------------------------------------------------------------------------------------------------------ ;Sample ;------------------------------------------------------------------------------------------------------------ Local $IconButtons[0] ;Array to manage Buttons Local $IconBLabels[0] ;Array to manage Buttons Local $ButtonPosLe = 10 ;Inserting Position X Local $ButtonPosTo = 10 ;Inserting Position Y Local $ButtonCount Local $MessageText Local $MessageTemp Local $IcPosOffset = 0 for $ButtonCount = 1 to 70 ;Jump to higher position after 60 Icons if $ButtonCount > 60 then $IcPosOffset = 265 _ArrayAdd($IconButtons, GUICtrlCreateButton("", $ButtonPosLe, $ButtonPosTo, 45, 45, $BS_ICON)) _ArrayAdd($IconBLabels, GUICtrlCreateLabel( -1 * ($ButtonCount + $IcPosOffset), $ButtonPosLe, $ButtonPosTo + 45, 45, 15)) GUICtrlSetStyle($IconBLabels[$ButtonCount - 1], BitOR($SS_CENTER, $SS_CENTERIMAGE)) $ButtonPosLe = $ButtonPosLe + 50 If Mod($ButtonCount, 10) = 0 Then $ButtonPosTo = $ButtonPosTo + 70 $ButtonPosLe = 10 EndIf ;retrieving Icons by negative ordinal position ;***************************************************************************************** $MessageTemp = GUICtrlSetImage($IconButtons[$ButtonCount - 1], "shell32.dll", -1 * ($ButtonCount + $IcPosOffset) , 1) ;***************************************************************************************** if $ButtonCount + $IcPosOffset = 1 or _ $ButtonCount + $IcPosOffset = 50 or _ $ButtonCount + $IcPosOffset = 51 or _ $ButtonCount + $IcPosOffset = 52 or _ $ButtonCount + $IcPosOffset = 53 or _ $ButtonCount + $IcPosOffset = 328 Then $MessageText = "Position: " & $ButtonCount + $IcPosOffset & " (of shell32.dll containing 327 Icons)" & @CRLF & @CRLF $MessageText = $MessageText & "Current GUICtrlSetImage return value is: " & $MessageTemp & @CRLF & @CRLF if $ButtonCount + $IcPosOffset <> 328 Then $MessageText = $MessageText & "But no Icon is retrieved... ." Else $MessageText = $MessageText & "As expected cose there are only 327 Icons... ." EndIf MsgBox($MB_SYSTEMMODAL, "Info", $MessageText, 0, $MainGUIWiHd) GUICtrlSetBkColor ($IconBLabels[$ButtonCount - 1], $COLOR_RED) EndIf If $ButtonCount + $IcPosOffset > 327 Then GUICtrlSetBkColor ($IconBLabels[$ButtonCount - 1], $COLOR_LIME) Next ;***************************************************************************************** $MessageText = "Retrieving by negative ordinal position, the first position fails." & @CRLF & @CRLF $MessageText = $MessageText & "Position 50 to 53 are also there but without Icon." & @CRLF & @CRLF $MessageText = $MessageText & "Starting from position 328 GUICtrlSetImage returns 0 (no more Icons)." & @CRLF & @CRLF ;***************************************************************************************** MsgBox($MB_SYSTEMMODAL,"Info", $MessageText, 0,$MainGUIWiHd) ;***************************************************************************************** $MessageText = "Trying with positive values, retrieving of position 1 works." & @CRLF & @CRLF $MessageText = $MessageText & "But 50 to 53 are stil without Icon... ." & @CRLF & @CRLF $MessageText = $MessageText & "This behavior seems inconsistent to me, considering that the function" & @CRLF $MessageText = $MessageText & "GUICtrlCreateICON is able to retrieve the first Icon by using -1... ." & @CRLF & @CRLF $MessageText = $MessageText & "Maybe is -1 a reserved value to the function GUICtrlSetIMAGE?" & @CRLF $MessageText = $MessageText & "Or is it a bug?" & @CRLF ;***************************************************************************************** MsgBox($MB_SYSTEMMODAL,"Info", $MessageText, 0,$MainGUIWiHd) $MessageTemp = GUICtrlSetImage($IconButtons[65], "shell32.dll", 1, 1) GUICtrlSetData($IconBLabels[65], 1) GUICtrlSetBkColor ($IconBLabels[65], $COLOR_YELLOW) $MessageTemp = GUICtrlSetImage($IconButtons[66], "shell32.dll", 50, 1) GUICtrlSetData($IconBLabels[66], 50) GUICtrlSetBkColor ($IconBLabels[66], $COLOR_YELLOW) $MessageTemp = GUICtrlSetImage($IconButtons[67], "shell32.dll", 51, 1) GUICtrlSetData($IconBLabels[67], 51) GUICtrlSetBkColor ($IconBLabels[67], $COLOR_YELLOW) $MessageTemp = GUICtrlSetImage($IconButtons[68], "shell32.dll", 52, 1) GUICtrlSetData($IconBLabels[68], 52) GUICtrlSetBkColor ($IconBLabels[68], $COLOR_YELLOW) $MessageTemp = GUICtrlSetImage($IconButtons[69], "shell32.dll", 53, 1) GUICtrlSetData($IconBLabels[69], 53) GUICtrlSetBkColor ($IconBLabels[69], $COLOR_YELLOW) ;============================================================================================================ ;GUI Loop ;============================================================================================================ While True ;------------------------------------------------------------------------------------------------------------ ;Get GUI-Messages ;------------------------------------------------------------------------------------------------------------ $MGUIGetMsg0 = GUIGetMsg() if $MGUIGetMsg0 = $GUI_EVENT_CLOSE Then ExitLoop ;------------------------------------------------------------------------------------------------------------ ;Get Traymenu Messages ;------------------------------------------------------------------------------------------------------------ Switch TrayGetMsg() Case $TrayMenExit ;Exit. ExitLoop EndSwitch ;------------------------------------------------------------------------------------------------------------ WEnd EndFunc Hope it works on your system... .
-
@JLogan3o13 Sorry and thanks! I'm still learning... . @BrewManNH Thank you for reply. Enumicon.au3 is a sample script witch is delivered and installed with AutoIt. AutoIt3\Examples\GUI\Advanced\enumicon.au3 The script uses first GUICtrlCreateIcon to create Icon-controls with displayed icons in one step. After this, it uses GUICtrlSetImage to change the Icons on a button-click. I wrote a similar script witch uses Buttons instead of Icon-Controls. If I try to change the first Icon (Index -1), the function doesn't returns the first Icon from shell32.dll. ; =============================================================================== ; ; Description: Show all icons in the given file ; Requirement(s): AutoIt 3.0.103+ ; Author(s): YDY (Lazycat) ; ; =============================================================================== #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ; Setting variables Global $g_aidIcons[30], $g_aidLabels[30] Global $g_iStartIndex = 1 Global $g_sFilename = @SystemDir & "\shell32.dll"; Default file is "shell32.dll" Global $g_iOrdinal = -1 Global $g_idPrev _Main() Func _Main() Local $iMsg, $sCurFilename, $sTmpFile ; Creating GUI and controls Local $hGui = GUICreate("Icon Selector by Ordinal value", 385, 435, @DesktopWidth / 2 - 192, _ @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES) GUICtrlCreateGroup("", 5, 1, 375, 40) GUICtrlCreateGroup("", 5, 50, 375, 380) Local $idFile = GUICtrlCreateInput($g_sFilename, 12, 15, 325, 16, -1, $WS_EX_STATICEDGE) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUICtrlSetTip(-1, "You can drop files from shell here...") Local $idFileSel = GUICtrlCreateButton("...", 345, 14, 26, 18) $g_idPrev = GUICtrlCreateButton("Previous", 10, 45, 60, 24, $BS_FLAT) GUICtrlSetState(-1, $GUI_DISABLE) Local $idNext = GUICtrlCreateButton("Next", 75, 45, 60, 24, $BS_FLAT) Local $idToggle = GUICtrlCreateButton("by Name", 300, 45, 60, 24, $BS_FLAT) ; This code build two arrays of ID's of icons and labels for easily update Local $iCurIndex For $iCntRow = 0 To 4 For $iCntCol = 0 To 5 $iCurIndex = $iCntRow * 6 + $iCntCol ;****************************************************************************************************** ;****************************************************************************************************** $g_aidIcons[$iCurIndex] = GUICtrlCreateIcon($g_sFilename, $g_iOrdinal * ($iCurIndex + 1), _ 60 * $iCntCol + 25, 70 * $iCntRow + 80) ConsoleWrite($g_iOrdinal * ($iCurIndex + 1)) ;****************************************************************************************************** ;My version vould have somthing like this: ;... $Button = GUICtrlCreateButton("", 100, 100, 25, 25, $BS_ICON).... ;... GUICtrlSetImage($Button, $g_sFilename, -1, 1).... ;****************************************************************************************************** ;****************************************************************************************************** $g_aidLabels[$iCurIndex] = GUICtrlCreateLabel($g_iOrdinal * ($iCurIndex + 1), _ 60 * $iCntCol + 11, 70 * $iCntRow + 115, 60, 20, $SS_CENTER) Next Next GUISetState() While 1 $iMsg = GUIGetMsg() ; Code below will check if the file is dropped (or selected) $sCurFilename = GUICtrlRead($idFile) If $sCurFilename <> $g_sFilename Then $g_iStartIndex = 1 $g_sFilename = $sCurFilename _GUIUpdate() EndIf ; Main "Select" statement that handles other events Select Case $iMsg = $idFileSel $sTmpFile = FileOpenDialog("Select file:", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Executables & dll's (*.exe;*.dll;*.ocx;*.icl)") If @error Then ContinueLoop GUICtrlSetData($idFile, $sTmpFile); GUI will be updated at next iteration Case $iMsg = $g_idPrev $g_iStartIndex = $g_iStartIndex - 30 _GUIUpdate() Case $iMsg = $idNext $g_iStartIndex = $g_iStartIndex + 30 _GUIUpdate() Case $iMsg = $idToggle If $g_iOrdinal = -1 Then $g_iOrdinal = 1 GUICtrlSetData($idToggle, "by Ordinal") WinSetTitle($hGui, "", "Icon Selector by Name value") Else $g_iOrdinal = -1 GUICtrlSetData($idToggle, "by Name") WinSetTitle($hGui, "", "Icon Selector by Ordinal value") EndIf _GUIUpdate() Case $iMsg = $GUI_EVENT_CLOSE Exit EndSelect WEnd EndFunc ;==>_Main ; Just updates GUI icons, labels and set state of "Previous" button Func _GUIUpdate() ConsoleWrite("start") Local $iCurIndex For $iCntRow = 0 To 4 For $iCntCol = 0 To 5 $iCurIndex = $iCntRow * 6 + $iCntCol ;****************************************************************************************************** ;****************************************************************************************************** GUICtrlSetImage($g_aidIcons[$iCurIndex], $g_sFilename, $g_iOrdinal * ($iCurIndex + $g_iStartIndex)) ;****************************************************************************************************** ;****************************************************************************************************** If $g_iOrdinal = -1 Then GUICtrlSetData($g_aidLabels[$iCurIndex], -($iCurIndex + $g_iStartIndex)) Else GUICtrlSetData($g_aidLabels[$iCurIndex], '"' & ($iCurIndex + $g_iStartIndex) & '"') EndIf Next Next ; This is because we don't want negative values If $g_iStartIndex = 1 Then GUICtrlSetState($g_idPrev, $GUI_DISABLE) Else GUICtrlSetState($g_idPrev, $GUI_ENABLE) EndIf EndFunc ;==>_GUIUpdate