Legendd Posted April 1, 2013 Share Posted April 1, 2013 I am beginner in the autoit programming. Would be necessary to simplify my code. expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Include <ScrollBarConstants.au3> #Include <GUIEdit.au3> #Region ### START Koda GUI section ### Form= $Title = "Installing Applications" $sText = "Preparing..." $Form1 = GUICreate($Title, 512, 216, -1, -1, -1) ;BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $Edit1 = GUICtrlCreateEdit($sText, 24, 64, 462, 128, BitOR($ES_AUTOVSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL)) $Progress1 = GUICtrlCreateProgress(24, 24, 462, 16) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $ms = 1000 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case Install() $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done.", 1) Sleep($ms) MsgBox(0,$Title,"Installation is complete.") ExitLoop EndSwitch WEnd Func Install() $a = 7 $e = 100 / $a $p = 0 $n = 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - 7-Zip...") Run("calc.exe") ; RunWait(@ScriptDir & "\7z922.exe" & " /S","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - Adobe Reader...") Run("calc.exe") ; RunWait(@ScriptDir & "\AdbeRdr_1000_en_US.exe" & " /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YES","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - Audacity®, the Free, Cross-Platform Sound Editor...") Run("calc.exe") ; RunWait(@ScriptDir & "\audacity-win-2.0.3.exe" & " /sp- /verysilent /norestart","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - Mozilla Firefox...") Run("calc.exe") ; RunWait(@ScriptDir & "\Firefox Setup 19.0.2" & " -ms","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - Skype...") Run("calc.exe") ; RunWait(@ScriptDir & "\SkypeSetupFull.exe" & " /noie /nogoogle /verysilent /norestart","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - VLC media player...") Run("calc.exe") ; RunWait(@ScriptDir & "\vlc-2.0.4-win32.exe" & " /S","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) $n = $n + 1 $p = $e * $n $aName = ("[" & $n & " of " & $a & "] - Winamp...") Run("calc.exe") ; RunWait(@ScriptDir & "\winamp563_full_emusic-7plus_all.exe" & " /S /install=SDRA","",@SW_HIDE) GuiCtrlSetData($Progress1, $p) $iEnd = StringLen(GUICtrlRead($Edit1)) _GUICtrlEdit_SetSel($Edit1, $iEnd, $iEnd) _GUICtrlEdit_Scroll($Edit1, $SB_SCROLLCARET) GUICtrlSetData($Edit1, " done." & @CRLF & $aName, 1) Sleep($ms) ; etc. EndFunc Link to comment Share on other sites More sharing options...
BrewManNH Posted April 1, 2013 Share Posted April 1, 2013 Seeing as how you're duplicating the code when installing programs, you should convert that into a function and call it for every installation, rather than just rewriting it 7 times. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Legendd Posted April 1, 2013 Author Share Posted April 1, 2013 if I rewrite it then the textbox does not work Link to comment Share on other sites More sharing options...
BrewManNH Posted April 1, 2013 Share Posted April 1, 2013 (edited) How about something like this? expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ScrollBarConstants.au3> #include <GUIEdit.au3> #region ### START Koda GUI section ### Form= $Title = "Installing Applications" $sText = "Preparing..." $Form1 = GUICreate($Title, 512, 216, -1, -1, -1) ;BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE)) $Edit1 = GUICtrlCreateEdit($sText, 24, 64, 462, 128, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL)) $Progress1 = GUICtrlCreateProgress(24, 24, 462, 16) GUISetState(@SW_SHOW) #endregion ### END Koda GUI section ### $ms = 1000 Install() Sleep($ms) MsgBox(0, $Title, "Installation is complete.") Func Install() $a = 7 $e = 100 / $a Local $aName[7][2] = [["7-Zip...", @ScriptDir & "\7z922.exe" & " /S"], _ ["Adobe Reader...", @ScriptDir & "\AdbeRdr_1000_en_US.exe" & _ " /sAll /msi /norestart ALLUSERS=1 EULA_ACCEPT=YES"], _ ["Audacity®, the Free, Cross-Platform Sound Editor...", _ @ScriptDir & "\audacity-win-2.0.3.exe" & " /sp- /verysilent /norestart"], _ ["Mozilla Firefox...", @ScriptDir & "\Firefox Setup 19.0.2" & " -ms"], _ ["Skype...", @ScriptDir & "\SkypeSetupFull.exe" & _ " /noie /nogoogle /verysilent /norestart"],["VLC media player...", _ @ScriptDir & "\vlc-2.0.4-win32.exe" & " /S"],["Winamp...", _ @ScriptDir & "\winamp563_full_emusic-7plus_all.exe" & " /S /install=SDRA"]] For $Loop = 1 To $a ;~ Run($aName[$Loop][1], "", @SW_HIDE) $p = $e * $Loop GUICtrlSetData($Edit1, "[" & $Loop & " of " & $a & "] - " & $aName[$Loop - 1][0] & @CRLF, "|") GUICtrlSetData($Progress1, $p) Sleep(1000) Next EndFunc ;==>Install This puts the name of the program to be installed in $aNames[x][0] and the string needed to run the installation in $aNames[x][1], it updates the progress bar and the Edit control, and doesn't need anything fancy. Don't forget the Run command in the For loop is commented out, so it won't actually install anything until uncommented. EDIT: Another thing, you might want to change my Run command with a RunWait, so it pauses the script until the installation is done before running the next one. Dumb mistake on my part. Also, if you do that, which you should, move everything that's after the Run command line to before the Run line, otherwise it won't update until the install is finished, which is probably not what you wanted. Edited April 1, 2013 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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