TiC01 Posted October 27, 2006 Share Posted October 27, 2006 (edited) Hi guys, I just wanted to show all of you my very FIRST auto-it script. I'm no programmer, so a terrible newbie at this, but still. I created this script to update my windows installation without any user interference. Ok, I could've used runonce(ex) or some other programs like XPlode, but I had my reasons for not using them. However, I know this script works (for my system anyway), but I also know that lots of it could have been programmed in a nicer way (probably). Since I want to learn more about this, I would like to ask all of you for suggestions and comments about whats wrong or could have done better. If anyone wants to use any of this, feel free to do so. Any help will be greatly appreciated UpdateOS.au3 expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.1.1.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <Array.au3> #include <file.au3> AutoItSetOption("ExpandEnvStrings",1) AutoItSetOption("TrayIconDebug",1) Global $apps_install Global $component_install Global $finalize Global $hotfix_dir Global $hotfix_install Global $reboot $config_file = @WorkingDir&"\UpdateOS.ini" Read_Config() If $component_install=1 Then Install_Components() If $hotfix_install=1 Then Install_Hotfix() If $apps_install=1 Then Install_Apps() If $finalize=1 Then Finalize() If (($component_install=1 Or $hotfix_install=1 Or $apps_install=1 Or $finalize=1) And $reboot=1) then Shutdown(6) Exit Func Read_Config() ; Check if configfile exists If FileExists($config_file) Then ; Read Configuration Options $apps_install = IniRead($config_file, "Config", "Apps_Install", 0) $component_install = IniRead($config_file, "Config", "Component_Install", 0) $finalize = IniRead($config_file, "Config", "Finalize", 0) $hotfix_install = IniRead($config_file, "Config", "Hotfix_Install", 0) $hotfix_dir = IniRead($config_file, "Config", "Hotfix_Path", 0) $reboot = IniRead($config_file, "Config", "Reboot", 0) ; Check if the directory supplied in the Configfile exist, otherwise disable the option If $hotfix_install==1 Then If FileExists($hotfix_dir)=False Then $hotfix_install=0 EndIf Else Exit EndIf EndFunc Func Install_Components() $components_found=0 ; Open the ini and count the number of times "[component_" exists in there $file = FileOpen($config_file, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $result = StringInStr(stringlower($line), "[component_") if $result=true then $components_found+=1 Wend FileClose($file) ProgressOn("Installing Components", "", "") ; For each component, get the number of lines For $current_item = 1 to $components_found $var = IniReadSection($config_file, "Component_" & $current_item) $title = False $titlename="" $command = False $commandname="" ; Read both items, compare and store them For $i = 1 To $var[0][0] Select Case $var[$i][0] = StringLower("title") $title=True $titlename=$var[$i][1] Case $var[$i][0] = Stringlower("cmdline") $command=True $commandname=$var[$i][1] EndSelect Next ; If both title and commandline are located, execute the commandline if($command=true and $title=true) then ProgressSet(($current_item/$components_found)*100 , Round(($current_item/$components_found)*100)&"%% Completed", "Installing " & $titlename ) RunWait($commandname) EndIf Next ProgressSet(100 , "Done", "All Components Installed") Sleep(1000) ProgressOff() ; Installation Complete EndFunc Func Install_Hotfix() ; Get number of files in hotfix directory $hotfix_nrfiles = DirGetSize($hotfix_dir,1) If IsArray($hotfix_nrfiles)==0 Then Exit ; Look for files with the KN*.exe pattern $hotfix_search = FileFindFirstFile($hotfix_dir&"KB*.exe") If $hotfix_search = -1 Then Exit ; Start installing hotfixes ; NOTE: ONLY TYPE2 FIXES ProgressOn("Updating Windows", "", "") For $i = 1 to $hotfix_nrfiles[1] Step 1 $hotfix_filename = FileFindNextFile($hotfix_search) If @error Then ExitLoop $hotfix_fullfile = $hotfix_dir & $hotfix_filename $hotfix_file_noext = StringTrimRight($hotfix_filename, 4) ProgressSet(($i/$hotfix_nrfiles[1])*100 , Round(($i/$hotfix_nrfiles[1])*100)&"%% Completed", "Installing Update [" & $i & "/" & $hotfix_nrfiles[1] & "] : " & $hotfix_file_noext ) RunWait($hotfix_fullfile & " /quiet /passive /norestart") Next FileClose($hotfix_search) ProgressSet(100 , "Done", "All Updates Installed") Sleep(1000) ProgressOff() ; Installation Complete EndFunc Func Install_Apps() $apps_found=0 ; Open the ini and count the number of times "[apps_" exists in there $file = FileOpen($config_file, 0) While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $result1 = StringInStr(stringlower($line), "[apps_") if $result1=true then $apps_found+=1 Wend FileClose($file) ProgressOn("Installing Applications", "", "") ; For each application, get the number of lines For $current_item = 1 to $apps_found $var = IniReadSection($config_file, "Apps_" & $current_item) $title = False $titlename="" $command = False $commandname="" $commandtype=0 Dim $commandmulti[10] Dim $commandnamemulti[10] For $y = 0 to 9 $commandmulti[$y]=False $commandnamemulti[$y]="" Next ; Check whether it's a single/multi cmdline application; Read all items, compare and store them For $i = 1 To $var[0][0] If StringInStr(StringLower($var[$i][0]),"cmdline")>0 then $commandtype=1 If StringInStr(StringLower($var[$i][0]),"cmdline_")>0 then $commandtype=2 Select Case $var[$i][0] = StringLower("title") $title=True $titlename=$var[$i][1] Case $commandtype=1 and StringInStr(StringLower($var[$i][0]),"cmdline")>0 $command=True $commandname=$var[$i][1] Case $commandtype=2 and StringInStr(StringLower($var[$i][0]),"cmdline_")>0 $len = StringLen($var[$i][0]) $x = StringRight($var[$i][0],$len-8) $commandmulti[$x-1]=True $commandnamemulti[$x-1]=$var[$i][1] EndSelect Next ; If both title and commandline(s) are located, execute the commandline(s) if($commandtype=1 And $command=true and $title=true) then ProgressSet(($current_item/$apps_found)*100 , Round(($current_item/$apps_found)*100)&"%% Completed", $titlename ) RunWait($commandname) EndIf If $commandtype=2 Then for $t = 0 to 9 if ($title=True And $commandmulti[$t]=True) Then ProgressSet(($current_item/$apps_found)*100 , Round(($current_item/$apps_found)*100)&"%% Completed", $titlename ) RunWait($commandnamemulti[$t]) EndIf Next EndIf Next ProgressSet(100 , "Done", "All Applications Installed") Sleep(1000) ProgressOff() ; Installation Complete EndFunc Func Finalize() Dim $szDrive, $szDir, $szFName, $szExt $section = IniReadSection($config_file, "Finalize") if Not @error then ProgressOn("Final Tasks", "", "") For $xx = 1 To $section[0][0] if StringLower($section[$xx][0])="action" then $action=StringSplit($section[$xx][1],",") Select Case StringLower($action[1])="createshortcut" And $action[0]=4 And FileExists($action[4]) ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Creating Shortcut" ) _PathSplit($action[4], $szDrive, $szDir, $szFName, $szExt) FileCreateShortcut($action[4],$action[3],$szDrive & StringLeft($szDir,StringLen($szDir)-1),"",$action[2]) Case StringLower($action[1])="dirdel" And $action[0]=2 And FileExists($action[2]) ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Removng Directory" ) DirRemove($action[2],1) Case StringLower($action[1])="filecopy" and FileExists($action[2]) And $action[0]=3 ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Copying File(s)" ) If Not StringRight($action[3],0)="\" Then $action[3]= $action[3]&"\" FileCopy($action[2], $action[3],9) Case StringLower($action[1])="filedel" And $action[0]=2 And FileExists($action[2]) ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Deleting File(s)" ) FileDelete($action[2]) Case StringLower($action[1])="filemove" And $action[0]=3 And FileExists($action[2]) ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Moving File(s)" ) If Not StringRight($action[3],0)="\" Then $action[3]= $action[3]&"\" FileMove($action[2], $action[3],9) Case StringLower($action[1])="run" And $action[0]=2 And FileExists($action[2]) ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Running Program" ) RunWait($action[2]) Case StringLower($action[1])="regadd" And $action[0]=5 ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Writing To Registry" ) RegWrite($action[2],$action[3],$action[4],$action[5]) Case Stringlower($action[1])="regdel" And $action[0]>=2 ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Deleting From Registry" ) If $action[0]=2 then $action[3]="" RegDelete($action[2],$action[3]) Case Else ProgressSet(($xx/$section[0][0])*100 , Round(($xx/$section[0][0])*100)&"%% Completed", "Skipping Item" ) EndSelect Sleep(250) EndIf Next ProgressSet(100 , "Done", "All Tasks Completed") Sleep(1000) ProgressOff() Else $finalize=0 EndIf EndFunc UpdateOS.ini expandcollapse popup[Config] Apps_Install=1 Component_Install=1 Finalize=1 Hotfix_Install=1 Hotfix_Path=%CDROM%\Addon\XPHotfix\ Reboot=1 [Component_1] Title=Package Installer 6.1.22.4 CmdLine=%CDROM%\Addon\XPProgs\PInstall.exe /quiet /passive /norestart [Component_2] Title=Windows Installer 3.1 CmdLine=%CDROM%\Addon\XPProgs\INST31.exe /quiet /passive /norestart [Component_3] Title=Windows Media Player 10 CmdLine=%CDROM%\Addon\XPProgs\MP10.exe /Q:A /R:N /C:"Setup_WM.exe /DisallowSystemRestore /Q:A /R:N" [Component_4] Title=Windows Media Connect 2.0 CmdLine=%CDROM%\Addon\XPProgs\WMCSetup.exe /quiet /passive /norestart [Component_5] Title=Windows Messenger 5.1 CmdLine=MSIEXEC /i %CDROM%\Addon\XPProgs\MSGR51.MSI /Q [Component_6] Title=MSN Messenger 7.5 CmdLine=MSIEXEC /i %CDROM%\Addon\XPProgs\MSN75.msi ADDEXPLORERTOOLBAR="" SETSEARCHENGINE="" SETHOMEPAGE="" /Quiet /Norestart [Component_7] Title=MacroMedia Flash Fix CmdLine=%CDROM%\Addon\XPProgs\Flash.exe /Q:A /R:N [Apps_1] Title=AC3-Filter 0.70b CmdLine=%CDROM%\Addon\Apps\AC3_070B.exe /S [Apps_2] Title=Alcohol 120% 1.9.5.3150 CmdLine_1=MSIEXEC /i %CDROM%\Addon\Apps\Alcohol\Setup.msi /NORESTART /QN CmdLine_2=%CDROM%\Addon\Apps\Alcohol\Alcohol.exe [Apps_3] Title=DVD-Decrypter 3.5.4.0 CmdLine=%CDROM%\Addon\Apps\Dvddecr.exe /S [Apps_4] Title=DVD-Shrink 3.2.0.15 CmdLine=%CDROM%\Addon\Apps\Dvdshrink.exe /VERYSILENT /SP- [Apps_5] Title=eMule 0.47 CmdLine_1=%CDROM%\Addon\Apps\eMule\eMule047.exe /S CmdLine_2=%CDROM%\Addon\Apps\eMule\eMuleCFG.exe [Apps_6] Title=Microsoft OfficeXP SP3 CmdLine_1=%CDROM%\Addon\Apps\OfficeXP\SetupPLS.exe TRANSFORMS=Unattended.MST /qn CmdLine_2=%CDROM%\Addon\Apps\OfficeXP\KB885884.exe /quiet /passive /norestart [Apps_7] Title=Microsoft PowerPoint Viewer 97 CmdLine=%CDROM%\Addon\Apps\PPV_97\Setup.exe /QNT /QT [Apps_8] Title=Nero Burning Rom 6.6.0.16 CmdLine=%CDROM%\Addon\Apps\Nero6.exe /NOCANCEL /NOLICENCE /NOREBOOT /NO_UI /SILENT /SN=xxxx-xxxx-xxxx-xxxx-xxxx-xxxx /WRITE_SN /NO_DESKTOPSHORTCUT [Apps_9] Title=Norton Antivirus 2005 CmdLine_1=%CDROM%\Addon\Apps\Nav05\Activate.exe CmdLine_2=%CDROM%\Addon\Apps\Nav05\NavSetup.exe "/qn /noreboot /REBOOT=ReallySuppress" [Apps_10] Title=Norton Partition Magic 8.05 CmdLine=%CDROM%\Addon\Apps\PQM805\Setup.exe /s /v"/qn" [Apps_11] Title=PcAnywhere 12 CmdLine=%CDROM%\Addon\Apps\PCA12.exe [Apps_12] Title=PowerDVD 5 CmdLine=%CDROM%\Addon\Apps\PowerDVD\Setup.exe -s -f2"%Systemdrive%\PowerDVD.log" [Apps_13] Title=Total Commander 6.55 CmdLine=%CDROM%\Addon\Apps\TCMD_655.EXE [Apps_14] Title=UltraIso Premium Edition 8 CmdLine_1=%CDROM%\Addon\Apps\UIso\uiso8_pe.exe /VERYSILENT /SP- CmdLine_2=%CDROM%\Addon\Apps\UIso\UltraIso.exe [Apps_15] Title=uTorrent 1.6 CmdLine=%CDROM%\Addon\Apps\uTorrent.exe [Apps_16] Title=VMWare Workstation 5.5 CmdLine_1=%CDROM%\Addon\Apps\VMWare\VMWare.exe /s /v"/qn REBOOT=REALLYSUPPRESS SERIALNUMBER=xxxxx-xxxxx-xxxxx-xxxxx ADDLOCAL=ALL DESKTOP_SHORTCUT=0 QUICKLAUNCH_SHORTCUT=1 DISABLE_AUTORUN=0 REMOVE_LICENSE=1" CmdLine_2=%CDROM%\Addon\Apps\VMWare\Prefs.exe [Apps_17] Title=VOptXP 7.22 CmdLine_1=%CDROM%\Addon\Apps\VOPTXP\VOPTXP.exe /s CmdLine_2=%CDROM%\Addon\Apps\VOPTXP\VOPT.exe [Apps_18] Title=WinRAR Corporate CmdLine=%CDROM%\Addon\Apps\WinRAR.exe [Apps_19] Title=XVid-Codec 1.1.0 CmdLine=%CDROM%\Addon\Apps\XVID110.exe /VERYSILENT /SP- [Finalize] Action=CreateShortcut,uTorrent,%APPDATA%\Microsoft\Internet Explorer\Quick Launch\uTorrent.lnk,%PROGRAMFILES%\uTorrent\uTorrent.exe Action=CreateShortcut,eMule,%APPDATA%\Microsoft\Internet Explorer\Quick Launch\eMule1.lnk,%PROGRAMFILES%\eMule\eMule.exe Action=DirDel,%USERPROFILE%\Favorites\LINKS Action=DirDel,%USERPROFILE%\Favorieten\Koppelingen Action=FileCopy,%CDROM%\Addon\Personal\Don.bmp,%ALLUSERSPROFILE%\Application Data\Microsoft\User Account Pictures Action=FileCopy,%USERPROFILE%\Start Menu\Programs\Windows Media Player.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileCopy,%ALLUSERSPROFILE%\Start Menu\Programs\eMule\eMule.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileCopy,%CDROM%\Addon\Apps\Nav05\NavCFG.exe,%PROGRAMFILES%\Norton AntiVirus Action=FileCopy,%ALLUSERSPROFILE%\Start Menu\Programs\Total Commander\Total Commander 32.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileCopy,%SystemDrive%\UpdateOS.ini,%ProgramFIles%\1\ Action=FileDel,%USERPROFILE%\Favorites\MSN.com.url Action=FileDel,%USERPROFILE%\Favorieten\MSN.com.url Action=FileDel,%USERPROFILE%\Favorties\Radio Station Guide.url Action=FileDel,%USERPROFILE%\Desktop\DVD Decrypter.lnk Action=FileDel,%USERPROFILE%\Desktop\DVD Shrink 3.2.lnk Action=FileDel,%ALLUSERSPROFILE%\Desktop\Norton Antivirus 2005.lnk Action=FileDel,%SYSTEMDRIVE%\PowerDVD.log Action=FileMove,%ALLUSERSPROFILE%\Desktop\Alcohol 120%%.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileMove,%ALLUSERSPROFILE%\Desktop\Symantec PcAnywhere.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileMove,%ALLUSERSPROFILE%\Desktop\PowerDVD.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=FileMove,%USERPROFILE%\Desktop\UltraISO.lnk,%APPDATA%\Microsoft\Internet Explorer\Quick Launch Action=Run,%CDROM%\Addon\Cmd\Recycle.exe Action=Run,%CDROM%\Addon\Personal\Favorite.exe Action=RegAdd,HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN,NAV CfgWiz,REG_SZ,%ProgramFiles%\Norton AntiVirus\NavCFG.exe Action=RegDel,HKLM\SOFTWARE\MICROSOFT\WINDOWS\CURRENTVERSION\RUN,WU_TICUpdateOS.au3UpdateOS.ini.txt Edited October 27, 2006 by TiC01 Link to comment Share on other sites More sharing options...
Ed_Maximized Posted October 27, 2006 Share Posted October 27, 2006 Interesting... Keep going!!! Wellcome to the forums!!! Ed ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
busysignal Posted October 28, 2006 Share Posted October 28, 2006 @TiC01, interesting implementation for a single installation. Nice work!If you want to make this a project to learn AutoIt3 then here are a few objectives to work on to improved your script.1.) Work on a GUI, this is allow easier configuration of the {.INI} and execution of your your selected applications. Not saying that modifing a text file is not a big deal A good example I found and used from the archives that might give you some good ideas.@blindwig (Jun 15 2005, 10:05 PM)http://www.autoitscript.com/forum/index.ph...elective+Launch@SvenP (Jan 18 2005, 02:33 PM)http://www.autoitscript.com/forum/index.ph...SPatchFunctions@sirhc (Sep 13 2005, 05:31 AM)http://www.autoitscript.com/forum/index.ph...760&hl=klipNote: This script is very complex but it is awesome! It has a wonderful GUI as an example.. Well, I hope some of code from the past inspires you to create an evolving project to help improve you skills..Enjoy AutoItCheers.. Link to comment Share on other sites More sharing options...
TiC01 Posted October 28, 2006 Author Share Posted October 28, 2006 Thank you both for your replies @busysignal, Thanks for the links. I will take a good look at them. I've been wandering around this forum for some time now (as a guest) and by searching and reading I think I've already learned a lot, but yet not enough I hope the links you gave will inspire me to further improve this project Link to comment Share on other sites More sharing options...
busysignal Posted October 29, 2006 Share Posted October 29, 2006 Thank you both for your replies @busysignal, Thanks for the links. I will take a good look at them. I've been wandering around this forum for some time now (as a guest) and by searching and reading I think I've already learned a lot, but yet not enough I hope the links you gave will inspire me to further improve this project I was thinking of something along your line of a Installation Script one that you can add items to and have a list of actions like what you listied in the [Finalize] section. Also, I had an idea of having a library of installation scripts for different applications. I noticed that you used (/) codes for different applications but sometimes you like to have key or click codes to installed a piece of software. I am not sure if you get the scope of what I was thinking. One the surface it looked like it would take not time at all then as I got into it that the project got a bit complex. BTW, there is a lot of code in the archives to achieve everything I think you are working towards. It just take some time to build all the functions and GUI to get it going.. Cheers.. Link to comment Share on other sites More sharing options...
TiC01 Posted October 29, 2006 Author Share Posted October 29, 2006 Hey B, The (/) codes used are the default Unattended installation settings for each program. I think by key/click codes you mean some way of autoIT installation scripts with send and mouseclick functions. Only thing is that I can't come up with an idea for the use of it. Could you give an example. ? Link to comment Share on other sites More sharing options...
busysignal Posted November 2, 2006 Share Posted November 2, 2006 Hey B,The (/) codes used are the default Unattended installation settings for each program. I think by key/click codes you mean some way of autoIT installation scripts with send and mouseclick functions. Only thing is that I can't come up with an idea for the use of it. Could you give an example. ?I have a few ideas about this.. Let me think about it and I will get some examples to you.Cheers.. 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