grimmlock Posted December 14, 2012 Author Posted December 14, 2012 (edited) It works. mIght need some minor tweaking but so far so good, THANK YOU! Next question when I add a second button and use this script I get an error about the "Case $Button_2" Error Variable used without being declared but it is in the local group. do I need to change the local groups to global? expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> Global $iBegin = 0 Main() Func Main() GUICreate("SB Batch File", 200, 320) ; will create a dialog box that when displayed is centered Local $Label1 = GUICtrlCreateLabel("Copy SpringBrook Databases", 10, 10, 200) Local $Label2 = GUICtrlCreateLabel("Copy DB 4 to 5: ", 20, 43, 75) Local $Label3 = GUICtrlCreateLabel("Copy DB 5 to 6: ", 20, 73, 75) Local $Label4 = GUICtrlCreateLabel("Output: ", 20, 103, 50) local $Button_1 = GUICtrlCreateButton("Run", 125, 35, 50) local $Button_2 = GUICtrlCreateButton("Run", 125, 65, 50) local $Button_3 = GUICtrlCreateButton("Ok", 125, 285, 50) Local $Edit_1 = GUICtrlCreateEdit("", 10, 123, 175, 150, BitOR(0x00200000,0x0800)) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() ; Use multiple arguments <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $GUI_EVENT_CLOSE, $Button_3 Exit Case $Button_1 ; Ask first <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If MsgBox(4, "Confirm", "Are you sure?") = 6 Then ; Check $var_1 here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $PID = Run("networkcomputer.domain.localTesttestA.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $sLine = StdoutRead($PID) ; An error arrives - possibly the bat file is not sending anything at the moment If @error Then ; So get a timestamp if one is not already set If Not $iBegin Then $iBegin = TimerInit() Else ; Or reset the timestamp $iBegin = 0 EndIf ; Send the data If StringLen($sLine) > 0 Then GUICtrlSetData($Edit_1, $sLine & @CRLF) ; Now see if a timestamp has been set and if we has exceeded the limit - here it is 10 secs If $iBegin And TimerDiff($iBegin) > 10 * 1000 Then ; If so then we exit ExitLoop EndIf WEnd If $PID Then MsgBox(0, "Success", "Succesfull") Else MsgBox(0, "Error", "Error") EndIf EndIf ; Was missing Case $Button_2 If MsgBox(4, "Confirm", "Are you sure?") = 6 Then Local $iPID = Run("networkcomputer.domain.localTestTest.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $tLine = StdoutRead($iPID) ; An error arrives - possibly the bat file is not sending anything at the moment If @error Then ; So get a timestamp if one is not already set If Not $iBegin Then $iBegin = TimerInit() Else ; Or reset the timestamp $iBegin = 0 EndIf ; Send the data If StringLen($tLine) > 0 Then GUICtrlSetData($Edit_1, $tLine & @CRLF) ; Now see if a timestamp has been set and if we has exceeded the limit - here it is 10 secs If $iBegin And TimerDiff($iBegin) > 10 * 1000 Then ; If so then we exit ExitLoop EndIf WEnd If $iPID Then MsgBox(0, "Success", "Succesfull") Else MsgBox(0, "Error", "Error") EndIf EndIf EndSwitch WEnd EndFunc Thanks Grimm Edited December 14, 2012 by grimmlock Thanks Grimm
kylomas Posted December 14, 2012 Posted December 14, 2012 grimmlock, $button_2 is working but you have an unmatched WEND. Maybe you need a WHILE 1 after this line If MsgBox(4, "Confirm", "Are you sure?") = 6 Then kylomas Forum Rules        Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
grimmlock Posted December 15, 2012 Author Posted December 15, 2012 Silly me, that was it. Thanks!! Grimm Thanks Grimm
Moderators Melba23 Posted December 15, 2012 Moderators Posted December 15, 2012 grimmlock,Could I suggest that you download and install the full SciTE4AutoIt3 package - you can find it here. Then when you run your scripts you also run a couple of errorchecking utilities which would help you identify simple errors like that. Plus you get a whole bunch of other interesting utilities to help you code in AutoIt as well. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Â
grimmlock Posted January 10, 2013 Author Posted January 10, 2013 using the code above, I changed one of the lines from Local $PID = Run ("NetworkComputer.domain.comRemotefile.bat", "", @SW_HIDE, $STDERR_CHILD + STDOUT_CHILD) To Run(@ComSpec & " /k psexec.exe NetworkComputer.domain.com -u domainuser -p password C:UsersPublicDesktopRemotefile.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) And I get the app does not display the output of the .bat file which is Echo Test. Any ideas as to why it will not display that output in the edit box? Thanks, Grimm Thanks Grimm
BrewManNH Posted January 10, 2013 Posted January 10, 2013 (edited) You have the logic set up incorrectly in the loops. Try this, I haven't really tried to deal with your timers but this should put the text into the edit box. expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> Global $iBegin = 0 Main() Func Main() GUICreate("SB Batch File", 200, 320) ; will create a dialog box that when displayed is centered Local $Label1 = GUICtrlCreateLabel("Copy SpringBrook Databases", 10, 10, 200) Local $Label2 = GUICtrlCreateLabel("Copy DB 4 to 5: ", 20, 43, 75) Local $Label3 = GUICtrlCreateLabel("Copy DB 5 to 6: ", 20, 73, 75) Local $Label4 = GUICtrlCreateLabel("Output: ", 20, 103, 50) Local $Button_1 = GUICtrlCreateButton("Run", 125, 35, 50) Local $Button_2 = GUICtrlCreateButton("Run", 125, 65, 50) Local $Button_3 = GUICtrlCreateButton("Ok", 125, 285, 50) Local $Edit_1 = GUICtrlCreateEdit("", 10, 123, 175, 150, BitOR(0x00200000, 0x0800)) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() ; Use multiple arguments <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $GUI_EVENT_CLOSE, $Button_3 Exit Case $Button_1 ; Ask first <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If MsgBox(4, "Confirm", "Are you sure?") = 6 Then ; Check $var_1 here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Run(@ComSpec & " /k psexec.exe \\NetworkComputer.domain.com -u domain\user -p password C:\Users\Public\Desktop\Remote\file.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $sLine = StdoutRead($PID) ; An error arrives - possibly the bat file is not sending anything at the moment If @error Then ; So get a timestamp if one is not already set If Not $iBegin Then $iBegin = TimerInit() Else ; Or reset the timestamp $iBegin = 0 EndIf ; Send the data If StringLen($sLine) > 0 Then GUICtrlSetData($Edit_1, $sLine & @CRLF) ; Now see if a timestamp has been set and if we has exceeded the limit - here it is 10 secs If $iBegin And TimerDiff($iBegin) > 10 * 1000 Then ; If so then we exit ExitLoop EndIf WEnd If $PID Then MsgBox(0, "Success", "Succesfull") Else MsgBox(0, "Error", "Error") EndIf EndIf ; Was missing Case $Button_2 If MsgBox(4, "Confirm", "Are you sure?") = 6 Then Run(@ComSpec & " /k psexec.exe \\NetworkComputer.domain.com -u domain\user -p password C:\Users\Public\Desktop\Remote\file.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $tLine = StdoutRead($iPID) ; An error arrives - possibly the bat file is not sending anything at the moment If @error Then ; So get a timestamp if one is not already set If Not $iBegin Then $iBegin = TimerInit() ExitLoop Else ; Or reset the timestamp $iBegin = 0 ; Send the data If StringLen($tLine) > 0 Then GUICtrlSetData($Edit_1, $tLine & @CRLF) EndIf WEnd ; Now see if a timestamp has been set and if we has exceeded the limit - here it is 10 secs If $iBegin And TimerDiff($iBegin) > 10 * 1000 Then ; If so then we exit ExitLoop EndIf EndIf If $iPID Then MsgBox(0, "Success", "Succesfull") Else MsgBox(0, "Error", "Error") EndIf ;~ EndIf EndSwitch WEnd EndFunc ;==>Main Edited January 10, 2013 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
grimmlock Posted January 10, 2013 Author Posted January 10, 2013 The interesting thing is that the only returned text in the edit box is C:UserscurrentuserDesktopAutoIT> is it because of the @comspec " /k psexec.... " ? Thanks Grimm Thanks Grimm
BrewManNH Posted January 10, 2013 Posted January 10, 2013 Use button 2 to test it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now