Jump to content

Recommended Posts

Posted (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?

#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 by grimmlock

Thanks

Grimm

Posted

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

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • 4 weeks later...
Posted

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

Posted (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.

#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 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 Gude
How 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

Posted

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

Posted

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 Gude
How 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

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
×
×
  • Create New...