Jump to content
Sign in to follow this  

Running a Set of Selected Scripts

Recommended Posts


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)
While 1
$msg = GUIGetMsg()
   Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton
   Case $msg = $okbutton
       For $i = 0 To UBound($CbxArray) - 1
           If BitAND(GUICtrlRead($CbxArray[$i]), $GUI_CHECKED) Then
               RunWait(GetProgramCommand(GUICtrlRead($CbxArray[$i], 1)))
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")

Return $command

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

#include <GUIConstants.au3>
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)
$DumpReg = GUICtrlCreateCheckbox("Dump Registry Hives",20,70,190,20)
$SysInfo = GUICtrlCreateCheckbox("Collect System Information",20,90,190,20)
$NetInfo = GUICtrlCreateCheckbox("Collect Network Information",20,110,190,20)

$GoButton = GUICtrlCreateButton("Run",20,270,100,20)
While 1          ; Wait for user to select checkboxes and then press the "Go" button to begin routines
    $msg = guigetmsg()
    Case $msg = $GUI_EVENT_CLOSE; If user closes the dialog box the program is ended
    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")
    if(GuiCtrlRead($DumpReg)  = 1) then
    ; Run registry hives
  RunWait(@ScriptDir & "\RegDump.au3")
    if(GuiCtrlRead($SysInfo)  = 1) then
    ; Run system information script
  RunWait(@ScriptDir & "\SysInfo.au3")
    if(GuiCtrlRead($NetInfo)  = 1) then
    ; Run network information script            
  RunWait(@ScriptDir & "\NetInfo.au3")

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

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

#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)
        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
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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.