Alek Posted December 1, 2007 Share Posted December 1, 2007 (edited) a small script that allows you to add programs to a list so that if the program crashes the Process watcher restarts it. expandcollapse popup#include <GUIConstants.au3> ;Declear all $Programs and creat all the needed arrays Global $Programs = 1 Global $Group[20] Global $Input[20] Global $Button[20][2] Global $Process[20] ;To create a window bar on the startmenu because we are using $WS_EX_TOOLWINDOW in the second gui ;We are hiding this one outside the screen $Task_Bar = GUICreate("",20,20,-100,-100) GUISetState() $Form1 = GUICreate("", 295, 100,-1,-1,-1,$WS_EX_TOOLWINDOW,$Task_Bar) $Group[$Programs] = GUICtrlCreateGroup("Program " & $Programs, 5, 5, 285, 70) $Input[$Programs] = GUICtrlCreateInput("", 10, 20, 245, 25) $Button[$Programs][0] = GUICtrlCreateButton("...", 260, 20, 25, 25, 0) $Button[$Programs][1] = GUICtrlCreateButton("Start", 10, 50, 276, 21, 0) $Button_Add = GUICtrlCreateButton("Add a Process",5,75,285,20) ;set the resizing so that they dont move when the gui changes size GUICtrlSetResizing($Group[$Programs],802) GUICtrlSetResizing($Input[$Programs],802) GUICtrlSetResizing($Button[$Programs][0],802) GUICtrlSetResizing($Button[$Programs][1],802) GUICtrlSetResizing($Button_Add,$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button_Add ;because i only decleard the arrays to 20 i needed to set a limit If $Programs < 20 Then ;Get the gui pos $Pos = WinGetPos($Form1) ;change the gui size to make room for the new controls WinMove($Form1,"",$Pos[0],$Pos[1],$Pos[2],$Pos[3]+75) ;set programs to +1 $Programs += 1 ;create the new controls at the new spot ;((75*$Programs)-75) creates a base position and the +# sets the position of the control $Group[$Programs] = GUICtrlCreateGroup("Program " & $Programs, 5, (75*$Programs)-75, 285, 70) GUICtrlSetResizing(-1,802) $Input[$Programs] = GUICtrlCreateInput("", 10, ((75*$Programs)-75)+20, 245, 25) GUICtrlSetResizing(-1,802) $Button[$Programs][0] = GUICtrlCreateButton("...", 260, ((75*$Programs)-75)+20, 25, 25, 0) GUICtrlSetResizing(-1,802) $Button[$Programs][1] = GUICtrlCreateButton("Start", 10, ((75*$Programs)-75)+50, 276, 21, 0) GUICtrlSetResizing(-1,802) EndIf EndSwitch ;check and see if any of the buttons was pressed For $x = 1 To $Programs ;Check if message = the .../browse button If $nMsg = $Button[$x][0] Then ;open the select file dialog $Dir = FileOpenDialog("","","(*.exe)") ;Set the data of the input to the new file GUICtrlSetData($Input[$x],$Dir) EndIf ;check if the Start/Stop button was pressed If $nMsg = $Button[$x][1] Then ;if the text on the start/stop button = start then If GUICtrlRead($Button[$x][1]) = "Start" And GUICtrlRead($Input[$x]) <> "" Then ;run the program and set the PID to $Process[$x] $Process[$x] = Run(GUICtrlRead($Input[$x])) ;change the button text to stop GUICtrlSetData($Button[$x][1],"Stop") Else ;else if the button text = Stop then ;Change the button text back to start GUICtrlSetData($Button[$x][1],"Start") ;Kill the process and wait for it to close While ProcessExists($Process[$x]) ProcessClose($Process[$x]) Sleep(1) WEnd EndIf EndIf ;Might as well throw in the restart function ;check if the text on the button = "stop" and if the processes is not runing and if the input is not empty ;also check if the file exists If GUICtrlRead($Button[$x][1]) = "Stop" And Not ProcessExists($Process[$x]) And GUICtrlRead($Input[$x]) <> "" And FileExists(GUICtrlRead($Input[$x])) Then ;Start a timer $Timer = TimerInit() ;run the program and set $Process[$x] to the new PID $Process[$x] = Run(GUICtrlRead($Input[$x])) ;Wait for it to start properly Do Sleep(1) Until ProcessExists($Process[$x]) Or TimerDiff($Timer) > 30000 ;If the timer is more then 30sec then there is proberly something wrong and stops the processes ;And sets the buttons text to Start to keep it from trying to restart it again If TimerDiff($Timer) > 30000 Then GUICtrlSetData($Button[$x][1],"Start") EndIf EndIf Next WEnd Edited December 1, 2007 by Alek [font="Impact"]Never fear, I is here.[/font] Link to comment Share on other sites More sharing options...
Kiesp Posted December 2, 2007 Share Posted December 2, 2007 very nice i like when u click add program the gui just expands.. looks cool this is gonna be usefull for me http://www.autoitscript.com/forum/index.php?showtopic=69911 <-- Best hacker ever :D Link to comment Share on other sites More sharing options...
ptrex Posted December 4, 2007 Share Posted December 4, 2007 @Alek, Very creative !! Nice coding. Regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
icadea Posted December 4, 2007 Share Posted December 4, 2007 nice one. thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now