Sign in to follow this  
Followers 0
SaintedRogue

Running a Set of Selected Scripts

5 posts in this topic

I am making a GUI for a series of scripts I have written. Basically, I want to be able to check off the script and have it run if selected. I came up with 2 variants, but neither work. This one will check the boxes however, when I press OK nothing happens:

#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Local $msg, $okbutton, $cancelbutton
GUICreate("Triage Recovery", 300, 400)
$okbutton = GUICtrlCreateButton("OK", 50, 200, 70, 20)
$cancelbutton = GUICtrlCreateButton("Cancel", 180, 200, 70, 20)
Dim $CbxArray[6]
$CbxArray[0] = GuiCtrlCreateCheckbox("Dump Memory", 10, 20, 120, 20)
$CbxArray[1] = guiCtrlCreateCheckbox("Dump Registry Hives", 10, 40, 120, 20)
$CbxArray[2] = GuiCtrlCreateCheckbox("System Information", 10, 60, 120, 20)
$CbxArray[3] = GuiCtrlCreateCheckbox("Network Information", 10, 80, 120, 20)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
   Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
       ExitLoop
   Case $msg = $okbutton
       For $i = 0 To UBound($CbxArray) - 1
           If BitAND(GUICtrlRead($CbxArray[$i]), $GUI_CHECKED) Then
               RunWait(GetProgramCommand(GUICtrlRead($CbxArray[$i], 1)))
           EndIf
       Next
EndSelect
WEnd
Func GetProgramCommand($program)
Local $command

Switch $program
   Case "Dump Memory"
       $command = RunWait(@ScriptDir & "\DumpMem.au3")
   Case "Dump Registry Hives"
       $command = RunWait(@ScriptDir & "\RegDump.au3")
   Case "System Information"
       $command = RunWait(@ScriptDir & "\SysInfo.au3")
   Case "Network Information"
    $command = RunWait(@ScriptDir & "\NetInfo.au3")
EndSwitch

Return $command
EndFunc

This one when I press OK the GUI goes away but my scripts do not run:

#include <GUIConstants.au3>
;AutoItSetOption("guioneventmode",1)
Global $DumpMem, $DumpReg, $SysInfo, $NetInfo
GUICreate("Clean Up Computer", 255, 350)
GUICtrlCreateLabel("Choose your Clean Up Tasks:", 12, 18)
$DumpMem = GUICtrlCreateCheckbox("Dump Memory",20,50,190,20)
    guictrlsetstate(4,$gui_checked)
$DumpReg = GUICtrlCreateCheckbox("Dump Registry Hives",20,70,190,20)
    guictrlsetstate(5,$gui_checked)
$SysInfo = GUICtrlCreateCheckbox("Collect System Information",20,90,190,20)
    guictrlsetstate(6,$gui_checked)
$NetInfo = GUICtrlCreateCheckbox("Collect Network Information",20,110,190,20)
    guictrlsetstate(7,$gui_checked)

$GoButton = GUICtrlCreateButton("Run",20,270,100,20)
GuiSetState()
While 1          ; Wait for user to select checkboxes and then press the "Go" button to begin routines
    $msg = guigetmsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended
        ExitLoop
   
    Case $msg = $GoButton      ; If user selects the Go button, all checked tasks will be run
                   
    if(GuiCtrlRead($DumpMem)  = 1) then   
    ; Run memory script
  RunWait(@ScriptDir & "\DumpMem.au3")
    EndIf  
    if(GuiCtrlRead($DumpReg)  = 1) then
    ; Run registry hives
  RunWait(@ScriptDir & "\RegDump.au3")
    EndIf
    if(GuiCtrlRead($SysInfo)  = 1) then
    ; Run system information script
  RunWait(@ScriptDir & "\SysInfo.au3")
    EndIf
    if(GuiCtrlRead($NetInfo)  = 1) then
    ; Run network information script            
  RunWait(@ScriptDir & "\NetInfo.au3")
    EndIf
        ExitLoop
    EndSelect
WEnd
Exit

Any suggestions on which of these will work the best, or easiest to get working?

Share this post


Link to post
Share on other sites



From help:

program The full path of the program (EXE, BAT, COM, or PIF) to run (see remarks).

I really doubt you can execute *.au3 scripts.

Compile them and try again using the compiled *.exe


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I have run into similar situations myself, where I have multiple scripts that will be called by the main script and want to test before actually compiling all the scripts. I agree with enaiman, where I have never been able to execute an .au3 script. However I have found that if your default action when clicking on a script is set to 'Run Script', you can execute it through a shell api.

ShellExecute( 'My_Test_Script.au3','', @ScriptDir & 'MyTestFolder' )

Or you could compile the scripts its to call upon before testing.

Edit: I would only use this for testing. .au3 files are only executable on machines that have AutoIt installed on them.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

That makes sense. I knew it would be something easy! Thanks all.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#Region Sample
    $i = _runScript('msgbox.au3', 0)
    MsgBox(64, 'Exitcode', 'RC: ' & $i)
    $i = _runScript('msgbox.au3', 1)
    MsgBox(64, 'Process ID', 'PID: ' & $i)
#EndRegion Sample

Func _runScript($sAu3, $iWait = 0)
    Local $i
    If Not @Compiled Then Return SetError(1, 0, 0)
    Select
        Case $iWait = 0 ;Returns when script exits, returns scripts exitcode
            $i = RunWait('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript "' & $sAu3 & '"')
            If @error Then Return SetError(2)
            Return $i
        Case $iWait = 1 ;Returns immidiatly returning scripts Process ID
            $i = Run('"' & @ScriptFullPath & '" /AutoIt3ExecuteScript "' & $sAu3 & '"')
            If @error Then Return SetError(2)
            Return $i
    EndSelect
EndFunc   ;==>_runScript

Edited by Djarlo

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  
Followers 0