Madman Posted January 5, 2007 Share Posted January 5, 2007 I made a program to start several program X seconds after each other. It's also checks if the process is allready running expandcollapse popup; MPS - Multi Program Starter ; Made by Madman ; Include Files #Include <GUIConstants.au3> #Include <GuiTreeView.au3> #include <File.au3> ; Check/Create file If not FileExists(@ScriptDir & "\Config.ini") Then _FileCreate(@ScriptDir & "\Config.ini") EndIf ; Create GUI parts $GUI = GUICreate("Multi program starter",800,400) $List = GUICtrlCreateTreeView(10,10,480,300,$TVS_CHECKBOXES,$WS_EX_CLIENTEDGE) $Sec = GUICtrlCreateInput("",20,330,20,20) GUICtrlCreateLabel("Seconds",45,333,45,20) $Add = GUICtrlCreateButton("Add",100,320,40,40) $Del = GUICtrlCreateButton("Remove",150,320,50,40) $Start = GUICtrlCreateButton("Start" & @CRLF & "checked" ,210,320,50,40,$BS_MULTILINE) $StartAll = GUICtrlCreateButton("Start" & @CRLF & "all",270,320,50,40,$BS_MULTILINE) $AutoStart = GUICtrlCreateCheckbox("Start checked on program start",330,330) $RunningProg = GUICtrlCreateLabel("",500,10,290,300,$SS_SUNKEN) ; Read config $SecRead = IniRead(@ScriptDir & "\Config.ini","Settings","Seconds","") GUICtrlSetData($Sec,$SecRead) $ProgramArray = IniReadSection(@ScriptDir & "\Config.ini","Programs") If Not @error Then For $i = 1 To $ProgramArray[0][0] $tree = GUICtrlCreateTreeViewItem($ProgramArray[$i][0],$List) If $ProgramArray[$i][1] = "CHECKED" Then GUICtrlSetState($tree,$GUI_CHECKED) EndIf Next EndIf $ReadAuto = IniRead(@ScriptDir & "\Config.ini","Settings","AutoStart","UNCHECKED") If $ReadAuto = "CHECKED" Then GUICtrlSetState($AutoStart,$GUI_CHECKED) GUISetState(@SW_SHOW); To Show GUI before lauching programs RunProgram("check") EndIf GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $Sec; Updated Sec IniWrite(@ScriptDir & "\Config.ini","Settings","Seconds",GUICtrlRead($Sec)) Case $msg = GUICtrlRead($List); Change to CHECK/UNCHECK in ini when doing it in GUI If GUICtrlRead($List) <> 0 Then $Read = IniRead(@ScriptDir & "\Config.ini","Programs",GUICtrlRead($List,1),"") If $Read = "CHECKED" Then If BitAND(GUICtrlRead(GUICtrlRead($List)), $GUI_UNCHECKED) = $GUI_UNCHECKED Then IniWrite(@ScriptDir & "\Config.ini","Programs",GUICtrlRead($List,1),"UNCHECKED") EndIF ElseIf $Read = "UNCHECKED" Then If BitAND(GUICtrlRead(GUICtrlRead($List)), $GUI_CHECKED) = $GUI_CHECKED Then IniWrite(@ScriptDir & "\Config.ini","Programs",GUICtrlRead($List,1),"CHECKED") EndIf EndIF EndIf Case $msg = $Del; Delte marked Program If GUICtrlRead($List) = 0 Then MsgBox(0,"Error!","Please mark program you wish to delete." & @CRLF & "Note: Not the checkboxes, click the text") ElseIf IniDelete(@ScriptDir & "\Config.ini","Programs",GUICtrlRead($List,1)) _GUICtrlTreeViewDeleteItem($GUI, $List, GUICtrlRead($List)) EndIf Case $msg = $Add; Add a program $Program = FileOpenDialog("Select Program",@WorkingDir,"Programs (*.exe)") IF $Program <> "" Then If IniRead(@ScriptDir & "\Config.ini","Programs",$Program,"") Then MsgBox(0,"Error!","Program allready listed") Else IniWrite(@ScriptDir & "\Config.ini","Programs",$Program,"UNCHECKED") GUICtrlCreateTreeViewItem($Program,$List) EndIf EndIf Case $msg = $StartAll; Start all, uncheck or not If GUICtrlRead($Sec) > 0 Then GUICtrlSetData($RunningProg,"") RunProgram("all") Else MsgBox(0,"Error!","You need to set seconds between program Start") EndIf Case $msg = $Start; Start only check programs If GUICtrlRead($Sec) > 0 Then GUICtrlSetData($RunningProg,"") RunProgram("check") Else MsgBox(0,"Error!","You need to set seconds between program Start") EndIf Case $msg = $AutoStart $ReadAuto = GUICtrlRead($AutoStart) If $ReadAuto = 1 Then IniWrite(@ScriptDir & "\Config.ini","Settings","AutoStart","CHECKED") Else IniWrite(@ScriptDir & "\Config.ini","Settings","AutoStart","UNCHECKED") EndIf Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd ; Function for run programs Func RunProgram($Switch) $ProgramArray = IniReadSection(@ScriptDir & "\Config.ini","Programs") If Not @error Then For $i = 1 To $ProgramArray[0][0] If $Switch == "check" Then If $ProgramArray[$i][1] = "CHECKED" Then $progSplit = StringSplit($ProgramArray[$i][0],"\") $nr = $progSplit[0] $process = $progSplit[$nr] If Not ProcessExists($process) Then Run($ProgramArray[$i][0]) Sleep(1000 * $Sec) Else GUICtrlSetData($RunningProg,GUICtrlRead($RunningProg) & $process & " is allready running" & @CRLF) EndIf EndIf ElseIf $Switch == "all" Then $progSplit = StringSplit($ProgramArray[$i][0],"\") $nr = $progSplit[0] $process = $progSplit[$nr] If Not ProcessExists($process) Then Run($ProgramArray[$i][0]) Sleep(1000 * $Sec) Else GUICtrlSetData($RunningProg,GUICtrlRead($RunningProg) & $process & " is allready running" & @CRLF) EndIf EndIf Next EndIf EndFunc 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