Jump to content

Batch Compile Scripts


Recommended Posts

I have only been using AutoIt for about a week(03.01.2005). I created templates for some of my testing needs. I'm sure it will evolve to more, but after I had made my templates I started to mass create scripts. I found it cumbersome to reopen all the scripts after modification to build them into an executable. So I created a simple program to do it for me using AutoIt. It's nothing to shout about, but feel free to use it if it suits your needs.

Batch_Compile.au3

Edited by Kerberuz

Kerby

Link to post
Share on other sites

I have only been using AutoIt for about a week(03.01.2005). I created templates for some of my testing needs. I'm sure it will evolve to more, but after I had made my templates I started to mass create scripts, I found it combersome to reopen all the scripts after modification to build them into an executable. So I created a simple program to do it for me using AutoIt. It's nothing to shout about, but feel free to use it if it suits your needs.

Batch_Compile.au3

<{POST_SNAPBACK}>

Hi o:) great job looks good but, look this exampel pls it is a

Batch Creator, Simplify Running Complex TasksBy Chaos945

it is very nice :lmao:

Thx to Chaos945 :)

Opt("RunErrorsFatal", 0) 
Opt("WinTitleMatchMode", 3) 
If WinExists("%_BatchCreator_%") Then Exit 
AutoItWinSetTitle("%_BatchCreator_%") 

HotKeySet( "{ESC}", "nothing" );unbinds the default ESC to quit hotkey 

GuiCreate("Batch Creator", 500, 341,(@DesktopWidth-500)/2, (@DesktopHeight-341)/2 , 0x04CF0000) 

#include "GUIConstants.au3" 
DIM $status 
$file_menu = GUICtrlCreateMenu ("&File") 
$addf_item = GUICtrlCreateMenuitem ("Add File",$file_menu) 
$addp_item = GUICtrlCreateMenuitem ("Add Path",$file_menu) 
$spce_item = GUICtrlCreateMenuitem ("",$file_menu) 
$saveb_item = GUICtrlCreateMenuitem ("Save Batch.. (CTRL+S)",$file_menu) 
$spce_item = GUICtrlCreateMenuitem ("",$file_menu) 
$exit_item = GUICtrlCreateMenuitem ("Exit (CTRL+Q)",$file_menu) 
$insert_menu = GUICtrlCreateMenu ("&Insert", -1) 
   $insert_cmd = GUICtrlCreateMenuitem ("DOS command", $insert_menu) 
$clear_menu = GUICtrlCreateMenuitem ("&Clear All", -1) 
$about_menu = GUICtrlCreateMenuitem ("&About", -1) 
$edit_lst = GuiCtrlCreateEdit("", 5, 5, 360, 250);[left, top ,width ,height] 
$lbl_bch = GuiCtrlCreateLabel("Batch Jobs:", 375, 5, 290, 20) 
$list_lst = GuiCtrlCreateList( "", 375, 20, 120, 210) 
$lload_bch = GuiCtrlCreateButton("Load", 375, 210, 60, 20) 
$delete_bch = GuiCtrlCreateButton("Delete", 435, 210, 60, 20) 
$launch_pr = GuiCtrlCreateButton("Launch", 5, 265, 360, 30) 
;$terminate_pr = GuiCtrlCreateButton("Terminate Batch", 5, 265, 360, 30) 
;GUICtrlSetState($terminate_pr, $GUI_HIDE) 
$statuslabel = GuiCtrlCreateLabel("Idle", 0, 300, 500, 20,BitOr($SS_SIMPLE,$SS_SUNKEN)) 

GUICtrlSetTip ($edit_lst, "Input batch commands here") 
GUICtrlSetTip ($list_lst, "Predefined batch files") 
GUICtrlSetTip ($lload_bch, "Loads selected batch file") 
GUICtrlSetTip ($delete_bch, "Deletes selected batch file") 

$fst_dta = FileFindFirstFile("*.bch");creates .bch files in the Batch List 
If $fst_dta <> -1 Then 
   $apnd_dta = FileFindNextFile( $fst_dta ) 
   Do 
      $apnd_dta = $apnd_dta & "|" & FileFindNextFile( $fst_dta ) 
   Until @error 
   GUICtrlSetData ($list_lst, $apnd_dta ) 
EndIf 

GuiSetState() 
While 1 
   If WinActive("Batch Creator") Then;prevets stealing hotkeys when the window is not active 
      HotKeySet( "^q", "gotoExit" ) 
      HotKeySet( "^s", "SaveFun" ) 
   Else 
      HotKeySet( "^q" ) 
      HotKeySet( "^s" ) 
   EndIf 
   $msg = GuiGetMsg() 
   Select 
   Case $msg = -3 
      GUIDelete() 
      ExitLoop 
   Case $msg = $launch_pr;Launch button pressed 
      RunList() 
   Case $msg = $addf_item;add file to edit list 
      $append = GuiCtrlRead($edit_lst); 
      $data_apnd = FileOpenDialog( "Select a file to add..", "", "All (*.*)", 1) 
      If $data_apnd = 1 Then $data_apnd = "" 
      $append = $append & $data_apnd 
      GUICtrlSetData ($edit_lst, $append); 
   Case $msg = $addp_item;add path to edit list 
      $append = GuiCtrlRead($edit_lst); 
      $append = $append & FileSelectFolder ( "Select a path to add..", 1); 
      GUICtrlSetData ($edit_lst, $append); 
   Case $msg = $saveb_item;save edit list as bch 
      SaveFun() 
   Case $msg = $insert_cmd;inserts @cmd 
      $append = GuiCtrlRead($edit_lst); 
      $append = $append & "@cmd"; 
      GUICtrlSetData ($edit_lst, $append) 
   Case $msg = $clear_menu;clear edit list 
      $append = GuiCtrlRead($edit_lst); 
      GUICtrlSetData ($edit_lst, ""); 
   Case $msg = $about_menu;show about 
      MsgBox(0, "About", "Batch Creator" & @CRLF & "Version 0.1 build 9" & @CRLF & @CRLF & "By chaos945@msn.com" & @CRLF & "Created with AutoIt3") 
   Case $msg = $lload_bch;load batch file 
      If GuiCtrlRead($list_lst) = "" Then 
         MsgBox(0, "Error", "No Batch Job selected") 
      Else 
         $bchld_rd = FileRead(GuiCtrlRead($list_lst), 9999) 
         GUICtrlSetData($edit_lst, $bchld_rd) 
      EndIf 
   Case $msg = $delete_bch;delete batch file 
      If GuiCtrlRead($list_lst) = "" Then 
         MsgBox(0, "Error", "No Batch Job selected") 
      Else 
         $confirm = MsgBox(32+4+262144, "", "Confirm delete batch?") 
         If $confirm = 6 Then 
            FileDelete(GuiCtrlRead($list_lst)) 
            lst_rfsh() 
         EndIF 
      EndIf 
   Case $msg = $exit_item;exit program 
      gotoExit() 
   Case Else 
    ;;; 
   EndSelect 
WEnd 
Exit 
    
Func RunList() 
   $launchstuff = GuiCtrlRead($edit_lst); 
   $items = stringsplit( $launchstuff, @LF); 
   For $i = 1 to $items[0] Step 1 
      GUICtrlSetState($launch_pr, $GUI_DISABLE) 
    ;GUICtrlSetState($terminate_pr, $GUI_SHOW) 
    ;Msgbox(0, "Debug - Launching", $items[$i] ); 
      GLOBAL $progrun = StringStripCR($items[$i]) 
    ;MsgBox(0,"Debug - Line " & $i,GUIGetMsg()) 
    ;If GUIGetMsg() = $terminate_pr Then 
    ;   CkStr() 
    ;   ProcessClose($progrun) 
    ;   ExitLoop 
    ;EndIf 
      If $progrun <> "" Then 
         If StringInStr( $progrun, "@cmd ") Then 
            $progrun = StringTrimLeft($progrun, 4) 
            GUICtrlDelete($statuslabel) 
            $statuslabel = GuiCtrlCreateLabel("Current Process: " & $progrun, 0, 300, 500, 20,BitOr($SS_SIMPLE,$SS_SUNKEN)) 
          ;Msgbox(0, "Debug - DOS commands", "@ComSpec" & " /c " & $progrun) 
            RunWait(@ComSpec & " /c " & $progrun) 
            $progrun = "cmd.exe" 
         Else 
            GUICtrlDelete($statuslabel) 
            $statuslabel = GuiCtrlCreateLabel("Current Process: " & $progrun, 0, 300, 500, 20,BitOr($SS_SIMPLE,$SS_SUNKEN)) 
            RunWait($progrun) 
         EndIf 
        ;If Not StringInStr($progrun, ".") Then 
        ;   If Not StringInStr($progrun, " ") Then 
        ;      $progrun = $progrun & ".exe" 
        ;   EndIf 
        ;ElseIf StringInStr($progrun, "ProcessIdleTasks") Then 
        ;   Processwait("wmiadap.exe") 
        ;   $progrun = "wmiadap.exe" 
        ;ElseIf $progrun = "cmd.exe" Then 
        ;  ;;;; 
        ;ElseIf StringInStr( $progrun, ".exe") Then 
        ;   $progrun = StringSplit( $progrun, ".exe") 
        ;   $progrun = $progrun & ".exe" 
        ;EndIf 
        ;ProcessWaitClose( $progrun ) 
      EndIf 
   Next 
  ;GUICtrlSetState($terminate_pr, $GUI_HIDE) 
   GUICtrlDelete($statuslabel) 
   $statuslabel = GuiCtrlCreateLabel("Idle", 0, 300, 500, 20,BitOr($SS_SIMPLE,$SS_SUNKEN)) 
   GUICtrlSetState($launch_pr, $GUI_ENABLE) 
EndFunc 

;Func CkStr() 
;   If Not StringInStr($progrun, ".") Then 
;      If Not StringInStr($progrun, " ") Then 
;         $progrun = $progrun & ".exe" 
;      EndIf 
;   ElseIf StringInStr($progrun, "ProcessIdleTasks") Then 
;      Processwait("wmiadap.exe") 
;      $progrun = "wmiadap.exe" 
;   ElseIf $progrun = "cmd.exe" Then 
;    ;;;; 
;   ElseIf StringInStr( $progrun, ".exe") Then 
;      $progrun = StringSplit( $progrun, ".exe") 
;      $progrun = $progrun & ".exe" 
;   EndIf 
;EndFunc 

Func lst_rfsh() 
   GUICtrlDelete($list_lst) 
   $list_lst = GuiCtrlCreateList( "", 375, 20, 120, 210) 
   $fst_dta = FileFindFirstFile("*.bch") 
   If $fst_dta <> -1 Then 
   $apnd_dta = FileFindNextFile( $fst_dta ) 
   Do 
      $apnd_dta = $apnd_dta & "|" & FileFindNextFile( $fst_dta ) 
   Until @error 
   GUICtrlSetData ($list_lst, $apnd_dta ) 
EndIf 

EndFunc 

Func nothing() 
EndFunc 

Func SaveFun() 
   If NOT WinActive( "Batch Creator" ) Then Return 
   $save_pth = FileSaveDialog( "Save batch as..", @ScriptDir, "Batch File (*.bch)", 16, "new.bch" ) 
   If NOT @error Then 
      If StringInStr($save_pth, ".bch", 1) = 0 Then $save_pth = $save_pth & ".bch" 
      FileDelete($save_pth) 
      FileWrite( $save_pth, GuiCtrlRead($edit_lst)) 
      lst_rfsh() 
   EndIf 
EndFunc 

Func gotoExit() 
   If NOT WinActive( "Batch Creator" ) Then 
      Return 
   Else 
      GUIDelete() 
      Exit 
   EndIf 
EndFunc
Edited by DirtyBanditos
Link to post
Share on other sites

HiĀ  o:) great job looks good but, look this exampel pls it is a

Batch Creator, Simplify Running Complex TasksBy Chaos945

it is very niceĀ  :lmao:

Thx to Chaos945 :)

There are a some good ideas :) in that script, currently I have no need for anything more than just compiling all my scripts to exe from one directory. I'd imagine in the future I could also add a que for compiling scripts from multiple directories or single files. It wouldn't take much to add that functionality.

FYI: When adding files or directories I noticed there were no line break so all items stayed on the same line.

Kerby

Link to post
Share on other sites

There are a some good ideas :) in that script, currently I have no need for anything more than just compiling all my scripts to exe from one directory. I'd imagine in the future I could also add a que for compiling scripts from multiple directories or single files. It wouldn't take much to add that functionality.

FYI: When adding files or directories I noticed there were no line break so all items stayed on the same line.

<{POST_SNAPBACK}>

Hello Kerberuz :) i think you have right look wat you need and adde it on your todo list on the futures^^ o:)

Your script is great dudu i have gif you a idea to adde any great futures to it:)

happy coding :lmao:

Edited by DirtyBanditos
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...