Didonet Posted November 22, 2007 Share Posted November 22, 2007 (edited) Windows Server Manager I use my PC for server, and on startup I have to run some programs... and thats the idea to create WSM Source: expandcollapse popup; Server Manager #include <GUIConstants.au3> #include <Constants.au3> Opt("TrayAutoPause",0) Opt("TrayIconHide",1) Opt("TrayMenuMode",1) Opt("GUICloseOnESC",0) Opt("RunErrorsFatal",0) $ini_file = @ScriptDir&"\run.ini" $title = "Windows Server Manager" ; GLOBALS Global $gui, $label_height, $label, $input, $run, $browse, $delete, $status Global $GUI_Height Global $ini_read 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+4096, $title, "Error! The file 'run.ini' is probably corupted or didn't exists." & @CRLF & "Creating new 'run.ini' file...") $file = FileOpen("run.ini", 2) If $file = -1 Then MsgBox(16+4096, "Error!", "Can't create .ini file. Check the folder permissions.") Exit EndIf FileWrite($file, "[settings]" & @CRLF & "refresh=on" & @CRLF & "startup=2" & @CRLF & "start-minimized=on" & @CRLF & "[run]" & @CRLF & "1=") FileClose($file) Global $ini_read = IniReadSection($ini_file, "run") Else Global $GUI_Height = guiHeight() EndIf EndFunc ReadINI() Func ExitEvent() If MsgBox(1+4096 + 0x20, "Exit", "Are you sure you want to exit?") = 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() GUIDelete() ReadINI() ShowGUI() EndFunc Func RunAll() For $l = 1 To $browse[0] Run(GUICtrlRead($input[$l])) If @error = 1 Then MsgBox(16, "Error: " & GUICtrlRead($input[$l]), "The program '" & GUICtrlRead($input[$l]) & "' does not exists!") 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[$split[0]] EndIf If ProcessExists($process) = 0 Then GuiCtrlSetData($row, "Stopped...") GUICtrlSetColor($row,0xff0000) Else GuiCtrlSetData($row, "Running...") GuiCtrlSetColor($row,0x00ff00) EndIf EndFunc Func SaveAll() Global $all_now, $a, $ini_file, $minimize_check, $refresh_check 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) EndFunc Func ShowGUI() FixINI() ReadINI() $label_height = 5 $gui = 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("Refresh status", 7, $GUI_Height - 55) GuiCtrlSetState(-1, $GUI_CHECKED) $minimize_check = GuiCtrlCreateCheckbox("Start minimized", 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("Start with 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("Time after start (sec.)", 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("Save all", 5, $GUI_Height - 30, 90) $runall_button = GUICtrlCreateButton("Start all", 100, $GUI_Height - 30, 120) $addprogram_button = GUICtrlCreateButton("Add program", 225, $GUI_Height - 30, 110) $exit_button = GUICtrlCreateButton("Exit", 340, $GUI_Height - 30, 55) GUISetState(@SW_SHOW) EndFunc ; Start program If IniRead($ini_file, "settings", "start-minimized", "") = "on" Then Opt("TrayIconHide",0) GUISetState(@SW_HIDE) Else ShowGUI() EndIf While 1 $msg = GUIGetMsg() $tMsg = TrayGetMsg() Select Case $msg = $addprogram_button $choseReturnADD = 0 ChoseFile(countINI()+1, '') If @error = 0 AND $choseReturnADD Then GuiDelete() IniWrite($ini_file, "run", countINI()+1, $choseReturnADD) $label_height +=25 ShowGUI() EndIf Case $msg = $start_time IniWrite($ini_file, "settings", 'startup', GuiCtrlRead($start_time)) 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, "Save all", "Are you sure you want to overwrite the settings and programs list?") = 1 Then SaveAll() EndIf Case $msg = $runall_button RunAll() Case $msg = $refresh_button GuiDelete() $gui = 'minimized' CheckGUI() Case $msg = $exit_button OR $msg = $GUI_EVENT_CLOSE ExitEvent() Case $tMsg = $TRAY_EVENT_PRIMARYDOWN ;Opt("TrayIconHide",1) GUISetState(@SW_SHOW,$gui) Case $msg = $GUI_EVENT_MINIMIZE Opt("TrayIconHide",0) GUISetState(@SW_HIDE,$gui) Case Else For $f = 1 To $browse[0] If $msg = $browse[$f] Then choseFile($f, $input[$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]), "The program '" & GUICtrlRead($input[$f]) & "' does not exists!") CheckStatus(GUICtrlRead($input[$f]), $status[$f]) ExitLoop EndIf If $msg = $delete[$f] Then If countINI() <> 1 Then If MsgBox(0x1 + 0x20, "Delete program", "Are you sure you want to delete '" & GuiCtrlRead($input[$f]) & "' from the list?") = 1 Then ;$GUI_Height -= $GUI_Add Global $GUI_Height = guiHeight() GuiDelete() IniDelete($ini_file, "run", $f) ReadINI() ShowGui() EndIf Else MsgBox(0x20, "Delete program", "You can't delete the last program!") EndIf ExitLoop EndIf Next EndSelect WEnd Func choseFile($x, $dir) $file = FileOpenDialog("Choose file...", $dir, "Applications (*.exe;*.bat;*.cmd;*.com)", 1) ;If $type = "input" Then If @error = 0 AND $dir <> '' Then GUICtrlSetData($input[$x], $file) SaveAll() EndIf If @error = 0 AND $dir = '' Then Global $choseReturnADD = $file EndIf ;EndIf ;If $type = "add" Then ; If @error = 0 Then GUICtrlSetData($input[$x], $file) ;EndIf EndFunc ;==>choseFile It have some bugs... and not everything works. For example when the "start minimized" is checked... it starts minimized, but when i try to show it up it wants to chose a file ) Waiting for comments... Edited November 22, 2007 by Didonet Link to comment Share on other sites More sharing options...
Didonet Posted November 26, 2007 Author Share Posted November 26, 2007 no comments? Link to comment Share on other sites More sharing options...
Generator Posted November 26, 2007 Share Posted November 26, 2007 no comments? Looks nice, but when you use it for the first time, the file will only register as the second one but not the first. Link to comment Share on other sites More sharing options...
Didonet Posted November 26, 2007 Author Share Posted November 26, 2007 I don't get it...? Register as second one but not the first? 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