Jump to content

Script included and called from GUI not finishing


Recommended Posts

HI all,

I'm trying to call a script (included) to execute a function and then return to the GUI. However the function doesn't run properly when called from a GUI. If I just Run from another script it works fine.

Do I need to do something else to make sure a function called from a included script runs properly and when finished return control to the GUI?

Please see my code below:

CODE
;scriptname: slave.au3

;function used to run commands

Func _RunCommand($command,$tool)

if $debug=1 then ConsoleWrite(" Starting " & $tool & @CRLF)

$ourproc = Run(@ComSpec & " /c " & $command, "", @SW_HIDE,$STDERR_CHILD)

While 1

$line = StderrRead($ourproc)

If @error Then ExitLoop

ConsoleWrite(" [X] WARNING: " & $line)

Wend

EndFunc

;scriptname=master.au3

#include <slave.au3>

#include <GUIConstants.au3>

#include <Constants.au3>

$mainwindow = GUICreate("Livelab Tool", 400, 300)

GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseClicked")

$button = GUICtrlCreateButton("Run", 20, 70, 80)

GUICtrlSetOnEvent($default_scan, "_MainFunction")

Func _MainFunction()

;Running NETSTAT

$command = "netstat -a >> netstat-a.log" ; Run command that will schedule installation of agentmon.exe

$tool="NETSTAT"

_RunCommand($command,$tool)

EndFunc

Link to comment
Share on other sites

HI all,

I'm trying to call a script (included) to execute a function and then return to the GUI. However the function doesn't run properly when called from a GUI. If I just Run from another script it works fine.

Do I need to do something else to make sure a function called from a included script runs properly and when finished return control to the GUI?

Please see my code below:

CODE
;scriptname: slave.au3

;function used to run commands

Func _RunCommand($command,$tool)

if $debug=1 then ConsoleWrite(" Starting " & $tool & @CRLF)

$ourproc = Run(@ComSpec & " /c " & $command, "", @SW_HIDE,$STDERR_CHILD)

While 1

$line = StderrRead($ourproc)

If @error Then ExitLoop

ConsoleWrite(" [X] WARNING: " & $line)

Wend

EndFunc

;scriptname=master.au3

#include <slave.au3>

#include <GUIConstants.au3>

#include <Constants.au3>

$mainwindow = GUICreate("Livelab Tool", 400, 300)

GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseClicked")

$button = GUICtrlCreateButton("Run", 20, 70, 80)

GUICtrlSetOnEvent($default_scan, "_MainFunction")

Func _MainFunction()

;Running NETSTAT

$command = "netstat -a >> netstat-a.log" ; Run command that will schedule installation of agentmon.exe

$tool="NETSTAT"

_RunCommand($command,$tool)

EndFunc

As far i can see your $button is not assigned!

It should call an function right?

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

As far i can see your $button is not assigned!

It should call an function right?

Cheers

oops. Yes sorry. Just fixed it. Even though the problem remains :-(. Any idea if I would need to do something to have the function properly run and returning control to the GUI?

thanks for your time reading this.

Link to comment
Share on other sites

oops. Yes sorry. Just fixed it. Even though the problem remains :-(. Any idea if I would need to do something to have the function properly run and returning control to the GUI?

thanks for your time reading this.

Ok...

In the first function: If without endif :whistle:

As far was i can see, work program is going to capture all ports(listening, established, etc...) And out put to the autoit console.

Witch is teh specific error?

No output in the screen?

No output file creation?

Create some msgbox in each execution to get a picture where the codes is being blocked!

With no error its a kind of difficult

P.S. - Missing also some loop to take capture of the buttons!

There are 2 ways to capture the buttons. are you using GUIOnEventMode?

cheers m8!

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

This may work better :whistle:

;scriptname: slave.au3

;scriptname=master.au3
#include <slave.au3>
#include <GUIConstants.au3>
#include <Constants.au3>
Opt('GUIOnEventMode', 1)
Global $debug

$mainwindow = GUICreate("Livelab Tool", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseClicked")
$button = GUICtrlCreateButton("Run", 20, 70, 80)
GUICtrlSetOnEvent($button, "_MainFunction")
GUISetState()

While 1
    Sleep(1000)
WEnd

Exit

Func _MainFunction()
    ;Running NETSTAT
    Local $command, $tool
    $command = "netstat -a >> netstat-a.log" ; Run command that will schedule installation of agentmon.exe
    $tool = "NETSTAT"
    _RunCommand($command, $tool)
EndFunc

;function used to run commands
Func _RunCommand($command, $tool)
    Local $ourproc, $line
    If $debug = 1 then ConsoleWrite(" [i] Starting " & $tool & @CRLF)
    $ourproc = Run(@ComSpec & " /c " & $command, "", @SW_HIDE, $STDERR_CHILD)

    While 1
        $line = StderrRead($ourproc)
        If @error Then ExitLoop
        ConsoleWrite(" [X] WARNING: " & $line)
    Wend
EndFunc

Func _CloseClicked()
    Exit
EndFunc
Link to comment
Share on other sites

This may work better :whistle:

;scriptname: slave.au3

;scriptname=master.au3
#include <slave.au3>
#include <GUIConstants.au3>
#include <Constants.au3>
Opt('GUIOnEventMode', 1)
Global $debug

$mainwindow = GUICreate("Livelab Tool", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseClicked")
$button = GUICtrlCreateButton("Run", 20, 70, 80)
GUICtrlSetOnEvent($button, "_MainFunction")
GUISetState()

While 1
    Sleep(1000)
WEnd

Exit

Func _MainFunction()
    ;Running NETSTAT
    Local $command, $tool
    $command = "netstat -a >> netstat-a.log" ; Run command that will schedule installation of agentmon.exe
    $tool = "NETSTAT"
    _RunCommand($command, $tool)
EndFunc

;function used to run commands
Func _RunCommand($command, $tool)
    Local $ourproc, $line
    If $debug = 1 then ConsoleWrite(" [i] Starting " & $tool & @CRLF)
    $ourproc = Run(@ComSpec & " /c " & $command, "", @SW_HIDE, $STDERR_CHILD)

    While 1
        $line = StderrRead($ourproc)
        If @error Then ExitLoop
        ConsoleWrite(" [X] WARNING: " & $line)
    Wend
EndFunc

Func _CloseClicked()
    Exit
EndFunc
Thanks a lot guys.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...