Didonet Posted October 12, 2007 Share Posted October 12, 2007 Hello, I want to create a startup manager.. but i have difficulty... This is my script for now... expandcollapse popup; Server Manager #include <GUIConstants.au3> $ini_file = "run.ini" $width = 0 $label_height = 5 $ini_read = IniReadSection($ini_file, "run") If @error Then MsgBox(4096, "", "Грешка! Най-вероятно липсва файла run.ini") Else For $i = 1 To $ini_read[0][0] $width = $width + 40 Next EndIf Func choseFile($x) $file = FileOpenDialog("Choose file...",@ScriptDir,"Изпълними програми (*.exe)", 1) If @error <> 1 Then GUICtrlSetData($input[$x] ,$file) EndFunc GUICreate(".:. Server Manager .:. v1", 300, $width) Dim $input[$i-1] Dim $browse[$i-1] For $x = 1 To $i-1 GuiCtrlCreateLabel($ini_read[$x][0] & '.', 5, $label_height+4) $input[$x-1] = GUICtrlCreateInput($ini_read[$x][1], 20, $label_height, 200) $browse[$x-1] = GUICtrlCreateButton("Browse...", 230, $label_height-1, 60, 22) $label_height = $label_height + 25 Next GUISetState(@SW_SHOW) $browze = GUICtrlCreateButton("LQLQ", 20, 20) While 1 $msg = GUIGetMsg() For $f = 0 To $i-1 Select $msg = GUIGetMsg() Case $msg = $browse[$f] choseFile($f) EndSelect Next Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_EVENT_MINIMIZE ExitLoop EndSelect WEnd I want the browse button to work to each field. How can i do that? I use a .ini file with the programs to run. Like that: [run] 1=C:/WINDOWS/calc.exe 2=C:/Program Files/Winamp/winamp.exe 3=C:/program.exe and etc... Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 12, 2007 Share Posted October 12, 2007 Study up on this version and how it works: expandcollapse popup; Server Manager #include <GUIConstants.au3> $ini_file = "run.ini" $GUI_Height = 40 $label_height = 5 $ini_read = IniReadSection($ini_file, "run") If @error Then MsgBox(4096, "", "??????! ???-???????? ?????? ????? run.ini") Exit ; Can't read .ini file Else $GUI_Height += 40 * $ini_read[0][0] EndIf GUICreate(".:. Server Manager .:. v1", 300, $GUI_Height) Dim $input[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $browse[$ini_read[0][0] + 1] = [$ini_read[0][0]] For $x = 1 To $ini_read[0][0] GUICtrlCreateLabel($ini_read[$x][0] & '.', 5, $label_height + 4) $input[$x] = GUICtrlCreateInput($ini_read[$x][1], 20, $label_height, 200) $browse[$x] = GUICtrlCreateButton("Browse...", 230, $label_height - 1, 60, 22) $label_height = $label_height + 25 Next $browze = GUICtrlCreateButton("LQLQ", 20, $GUI_Height - 35) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_EVENT_MINIMIZE ExitLoop Case $msg = $browze MsgBox(32, "LQLQ", "What's this button for???") Case Else For $f = 1 To $browse[0] If $msg = $browse[$f] Then choseFile($f) ExitLoop EndIf Next EndSelect WEnd Func choseFile($x) $file = FileOpenDialog("Choose file...", @ScriptDir, "????????? ???????? (*.exe)", 1) If @error = 0 Then GUICtrlSetData($input[$x], $file) EndFunc ;==>choseFile The vertical spacing in the GUI is not quite right, but the functionality is there. Note that all of the arrays ($ini_read, $input, and $browse) have the count in the first 0-based element, and the [1] thru [n] elements hold the interesting data. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Didonet Posted October 12, 2007 Author Share Posted October 12, 2007 (edited) Thanks a lot!!! :P p.s.: the button "lqlq" is just for test Edited October 12, 2007 by Didonet Link to comment Share on other sites More sharing options...
Didonet Posted October 12, 2007 Author Share Posted October 12, 2007 a new problem.. i create a button "run" to each line but i have a problem with the Case... I use that : Case Else for the $browse[] but how can i use $run[]? expandcollapse popup; Server Manager #include <GUIConstants.au3> $ini_file = "run.ini" $GUI_Height = 40 $label_height = 5 $ini_read = IniReadSection($ini_file, "run") If @error Then MsgBox(4096, "", "Грешка! Най-вероятно липсва файла run.ini") Exit ; Can't read .ini file Else $GUI_Height += 40 * $ini_read[0][0] EndIf GUICreate(".:. Server Manager .:. v1", 400, $GUI_Height) Dim $input[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $run[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $browse[$ini_read[0][0] + 1] = [$ini_read[0][0]] For $x = 1 To $ini_read[0][0] GUICtrlCreateLabel($ini_read[$x][0] & '.', 5, $label_height + 4) $input[$x] = GUICtrlCreateInput($ini_read[$x][1], 20, $label_height, 200) $run[$x] = GUICtrlCreateButton("run", 225, $label_height - 1, 30, 22) $browse[$x] = GUICtrlCreateButton("Browse...", 260, $label_height - 1, 60, 22) $label_height = $label_height + 25 Next ;$browze = GUICtrlCreateButton("LQLQ", 20, $GUI_Height - 35) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_EVENT_MINIMIZE ExitLoop Case Else For $f = 1 To $browse[0] If $msg = $browse[$f] Then choseFile($f) ExitLoop EndIf Next EndSelect WEnd Func choseFile($x) $file = FileOpenDialog("Choose file...", @ScriptDir, "Изпълними програми (*.exe)", 1) If @error = 0 Then GUICtrlSetData($input[$x], $file) EndFunc ;==>choseFile Link to comment Share on other sites More sharing options...
Didonet Posted October 12, 2007 Author Share Posted October 12, 2007 up? Link to comment Share on other sites More sharing options...
PsaltyDS Posted October 13, 2007 Share Posted October 13, 2007 a new problem.. i create a button "run" to each line but i have a problem with the Case... I use that : Case Else for the $browse[] but how can i use $run[]? Just check for the run buttons in the same loop that checks the browse buttons: While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $GUI_EVENT_MINIMIZE ExitLoop Case Else For $f = 1 To $browse[0] If $msg = $browse[$f] Then choseFile($f) ExitLoop EndIf If $msg = $run[$f] Then MsgBox(64, "Run", "Running " & $f & ": " & GUICtrlRead($input[$f])) EndIf Next EndSelect WEnd Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Didonet Posted October 13, 2007 Author Share Posted October 13, 2007 u are... genius 0.oThanks again!I'm searching in the help file for function to convert the GUICtrlRead($input[$f]) to the reverse...for example:C:/Windows/file.exetoexe.elif/swodniw/:cand explode ( http://php.net/explode ) the first "/"and again reverse to get only that:file.exeand checkIf ProcessExists("file.exe") Then...is there another way to check that the process in the input is running? Link to comment Share on other sites More sharing options...
Achilles Posted October 13, 2007 Share Posted October 13, 2007 u are... genius 0.o Thanks again! I'm searching in the help file for function to convert the GUICtrlRead($input[$f]) to the reverse... for example: C:/Windows/file.exe to exe.elif/swodniw/:c and explode ( http://php.net/explode ) the first "/" and again reverse to get only that: file.exe and check If ProcessExists("file.exe") Then ... is there another way to check that the process in the input is running? Just a suggestion that is probably useless but you could try WinExists if their is any window in the process you're checking. Also, make sure that your code for getting just the filename is working correctly, like have it check with a msgbox so you can see that it is checking for the exact process name you want it to check. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Didonet Posted October 15, 2007 Author Share Posted October 15, 2007 These days I have problems with my I-net and I was forced to work offline ;[ Only with Auto-IT Manual. This is what I made for now: expandcollapse popup; Server Manager #include <GUIConstants.au3> #include <Array.au3> #NoTrayIcon Opt("TrayOnEventMode", 2) Opt("TrayMenuMode", 1) Opt("RunErrorsFatal", 0) $tray_open = TrayCreateItem("Отвори") TrayItemSetOnEvent(-1, "CheckGUI") $tray_exit = TrayCreateItem("Изход") TrayItemSetOnEvent(-1,"ExitEvent") TraySetState() $ini_file = "run.ini" $title = ".:. Windows Server Manager .:." ; GLOBALS Global $label_height Global $label Global $input Global $run Global $browse Global $delete Global $status Global $startos_check Global $refresh_check Global $start_time Global $minimize_check Global $refresh_button Global $saveall_button Global $runall_button Global $addprogram_button Global $exit_button Global $r ; GLOBALS Func ReadINI() Global $ini_read = IniReadSection($ini_file, "run") If @error Then MsgBox(48, $title, "Грешка! Файла 'run.ini' най-вероятно липсва или е повреден." & @CRLF & "Създавам нов 'run.ini' файл...") $file = FileOpen("run.ini", 2) If $file = -1 Then MsgBox(0, "Грешка", "Не мога да създам файла. Моля проверете правата на папката.") Exit EndIf FileWrite($file, "[settings]" & @CRLF & "refresh=on" & @CRLF & "startup=2" & @CRLF & "start-minimized=on" & @CRLF & "[run]" & @CRLF & "1=") FileClose($file) Else Global $GUI_Height = guiHeight() EndIf EndFunc ReadINI() Func ExitEvent() If MsgBox(0x1 + 0x20, "Изход от програмата", "Сигурни ли сте, че искате да излезете?") = 1 Then Exit EndFunc Func guiHeight() $i = 0 For $x = 1 To $ini_read[0][0] $i += 1 Next Return 110 + 25 * $i EndFunc Func countINI() $i = 0 For $x = 1 To $ini_read[0][0] $i += 1 Next Return $i EndFunc Func FixINI() For $x = 1 To countINI() If $ini_read[$x][0] <> $x Then IniDelete($ini_file, "run", $ini_read[$x][0]) IniWrite($ini_file, "run", $x, $ini_read[$x][1]) EndIf Next EndFunc Func CheckGUI() Global $gui If $gui = "minimized" Then ReadINI() ShowGUI() ; GUISetState(@SW_SHOW) EndIf EndFunc Func RunAll() For $l = 1 To $browse[0] Run(GUICtrlRead($input[$l])) If @error = 1 Then MsgBox(16, "Error: " & GUICtrlRead($input[$l]), "Програмата '" & GUICtrlRead($input[$l]) & "' не съществува!") Else GuiCtrlSetData($status[$l], "Running...") GuiCtrlSetColor($status[$l],0x00ff00) Sleep(GuiCtrlRead($start_time) * 1000) EndIf Next EndFunc Func CheckStatus($process, $row) If StringInStr($process, "\") And StringInStr($process, ".exe") And FileExists($process) Then $split = StringSplit($process, "\") $process = $split[_ArrayMax($split)] EndIf If ProcessExists($process) = 0 Then GuiCtrlSetData($row, "Stopped...") GUICtrlSetColor($row,0xff0000) Else GuiCtrlSetData($row, "Running...") GuiCtrlSetColor($row,0x00ff00) EndIf EndFunc Func ShowGUI() FixINI() ReadINI() $label_height = 5 TrayItemSetState($tray_open, 128) GUICreate($title, 400, $GUI_Height) GUICtrlCreateLabel ('',0,$GUI_Height-85, 400,1,BitOr($SS_SIMPLE,$SS_SUNKEN)) Dim $label[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $input[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $run[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $browse[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $delete[$ini_read[0][0] + 1] = [$ini_read[0][0]] Dim $status[$ini_read[0][0] + 1] = [$ini_read[0][0]] For $x = 1 To $ini_read[0][0] $label[$x] = GUICtrlCreateLabel($ini_read[$x][0] & '.', 3, $label_height + 4, 15, 20, $SS_RIGHT) $input[$x] = GUICtrlCreateInput($ini_read[$x][1], 22, $label_height, 200) GUICtrlSetBkColor(-1, 0xd2d2d2) $run[$x] = GUICtrlCreateButton("run", 225, $label_height - 1, 30, 22) $browse[$x] = GUICtrlCreateButton("Browse...", 258, $label_height - 1, 60, 22) $delete[$x] = GUICtrlCreateButton("X", 320, $label_height - 1, 17, 22) $status[$x] = GuiCtrlCreateLabel("Status...", 340, $label_height + 2, 55, 15) GUICtrlSetBkColor(-1, 0xd2d2d2) CheckStatus($ini_read[$x][1], $status[$x]) $label_height += 25 $r += 1 Next $refresh_check = GuiCtrlCreateCheckbox("Обновявай статуса", 7, $GUI_Height - 55) GuiCtrlSetState(-1, $GUI_CHECKED) $minimize_check = GuiCtrlCreateCheckbox("Стартирай минимизиран", 7, $GUI_Height - 80) If IniRead($ini_file, "settings", "start-minimized", "") = "on" Then GuiCtrlSetState(-1, $GUI_CHECKED) Else GUICtrlSetState(-1, $GUI_UNCHECKED) EndIf $startos_check = GuiCtrlCreateCheckbox("Стартирай с OS", 295, $GUI_Height - 80) If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "WSM") = "" Then GuiCtrlSetState(-1, $GUI_UNCHECKED) Else GuiCtrlSetState(-1, $GUI_CHECKED) EndIf GuiCtrlCreateLabel("Време след старт (сек.)", 185, $GUI_Height - 52) $start_time = GuiCtrlCreateInput(IniRead($ini_file, "settings", "startup", "2"), 140, $GUI_Height - 55, 40, 20) GuiCtrlCreateUpDown($start_time) $refresh_button = GuiCtrlCreateButton("Refresh", 340, $GUI_Height - 60, 55) $saveall_button = GUICtrlCreateButton("Запази всички", 5, $GUI_Height - 30, 90) $runall_button = GUICtrlCreateButton("Стартирай всички", 100, $GUI_Height - 30, 120) $addprogram_button = GUICtrlCreateButton("Добави програма", 225, $GUI_Height - 30, 110) $exit_button = GUICtrlCreateButton("Изход", 340, $GUI_Height - 30, 55) GUISetState(@SW_SHOW) EndFunc ShowGUI() While 1 $msg = GUIGetMsg() Select Case $msg = $addprogram_button IniWrite($ini_file, "run", countINI()+1, "") GuiDelete() $label_height +=25 ShowGUI() Case $msg = $minimize_check If GuiCtrlRead($minimize_check) = 1 Then IniWrite($ini_file, "settings", "start-minimized", "on") Else IniWrite($ini_file, "settings", "start-minimized", "off") EndIf Case $msg = $startos_check If GuiCtrlRead($startos_check) = 1 Then RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "WSM", "REG_SZ", "'" & @ScriptFullPath & "'") Else RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "WSM") EndIf Case $msg = $saveall_button If MsgBox(0x1 + 0x20, "Запис на приложенията", "Сигурни ли сте, че искате да презапишете списъка и настройките?") = 1 Then Dim $all_now Dim $a For $w = 1 To $label[0] IniWrite($ini_file, "run", $ini_read[$w][0], GuiCtrlRead($input[$w])) Next If GuiCtrlRead($minimize_check) <> 1 Then $minimize = 'off' Else $minimize = 'on' EndIf If GuiCtrlRead($refresh_check) <> 1 Then $refresh = 'off' Else $refresh = 'on' EndIf IniWrite($ini_file, "settings", 'refresh', $refresh) IniWrite($ini_file, "settings", 'startup', GuiCtrlRead($start_time)) IniWrite($ini_file, "settings", 'start-minimized', $minimize) EndIf Case $msg = $runall_button RunAll() Case $msg = $refresh_button GuiDelete() $gui = 'minimized' CheckGUI() Case $msg = $exit_button ExitEvent() Case $msg = $GUI_EVENT_CLOSE ;GUIDelete() ;$gui = "minimized" ;TrayItemSetState($tray_open, 64) ExitEvent() Case $msg = $GUI_EVENT_MINIMIZE GUIDelete() $gui = "minimized" TrayItemSetState($tray_open, 64) Case Else For $f = 1 To $browse[0] If $msg = $browse[$f] Then choseFile($f) CheckStatus(GUICtrlRead($input[$f]), $status[$f]) ExitLoop EndIf If $msg = $run[$f] Then Run(GUICtrlRead($input[$f])) If @error = 1 Then MsgBox(16, "Error: " & GUICtrlRead($input[$f]), "Програмата '" & GUICtrlRead($input[$f]) & "' не съществува!") CheckStatus(GUICtrlRead($input[$f]), $status[$f]) ExitLoop EndIf If $msg = $delete[$f] Then If countINI() <> 1 Then If MsgBox(0x1 + 0x20, "Изтриване на приложение", "Сигурни ли сте, че искате да изтриете програмата '" & GuiCtrlRead($input[$f]) & "' от списъка?") = 1 Then ;$GUI_Height -= $GUI_Add Global $GUI_Height = guiHeight() GuiDelete() IniDelete($ini_file, "run", $f) ReadINI() ShowGui() EndIf Else MsgBox(0x20, "Изтриване на приложение", "Не можете да изтриете последната програма в списъка!") EndIf ExitLoop EndIf Next EndSelect WEnd Func choseFile($x) $file = FileOpenDialog("Choose file...", @ScriptDir, "Изпълними програми (*.exe)", 1) ;If $type = "input" Then If @error = 0 Then GUICtrlSetData($input[$x], $file) ;EndIf ;If $type = "add" Then ; If @error = 0 Then GUICtrlSetData($input[$x], $file) ;EndIf EndFunc ;==>choseFile What's your comment? And... how can i make this option works: When is checked $minimize_check if the program is started to minimize it automaticly... but when i minimize it i can't restore it back... Link to comment Share on other sites More sharing options...
weaponx Posted October 15, 2007 Share Posted October 15, 2007 This line is wrong $split = StringSplit($process, "\") $process = $split[_ArrayMax($split)]_ArrayMax returns the highest value in the array, not the highest element.Any time you do a StringSplit() the last element is stored in the first element of the array. Do this instead. $split = StringSplit($process, "\") $process = $split[$split[0]] Link to comment Share on other sites More sharing options...
Didonet Posted October 15, 2007 Author Share Posted October 15, 2007 i think i need the highest value.. ? or not? To check is the process started... 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