Sign in to follow this  
Followers 0
skysel

Script optimisation

9 posts in this topic

Hello AutoIt people :) I don't really have a problem with script below, but I am just wondering if there's any way to further optimize it? Maybe some functions not very well used, etc... well, here it is:

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <String.au3>
#include <INet.au3>
#notrayicon
#AutoIt3Wrapper_icon=au3.ico

$intWindowWidth = round(600,0)
$intWindowHeight = round(440,0)

$objWindow  = GUICreate("Installer...",$intWindowWidth,$intWindowHeight)
GUISetState()

GuiCTRLCreatePic('\\domain.local\Software\_Install\_Default\1\image.jpg', 0, 0, 600, 440)
GUICtrlSetState( -1, $GUI_DISABLE)

    GUICtrlCreateLabel("Adobe, QuickTime, Real, CutePDF, FlashPlayer, SMPlayer, 7zip, FireFox. NOD32 NI vkljucen v instalacijo. ", 165, 55, 361, 26)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab11OK = GUICtrlCreateButton("Namesti programe", 30, 55, 120, 25)
    GUICtrlCreateLabel("Namesti Navision + IMS komunikacijo.", 165, 105, 260, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab12OK = GUICtrlCreateButton("Navision + IMS", 30, 100, 120, 25)
    GUICtrlCreateLabel("Namesti Java Customer Center.", 165, 150, 260, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab13OK = GUICtrlCreateButton("Customer Center", 30, 145, 120, 25)
    GUICtrlCreateLabel("Avaya novi software + Wallboard IP: 10.15.10.52", 165, 195, 350, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab14OK = GUICtrlCreateButton("Avaya Software", 30, 190, 120, 25)
    GUICtrlCreateLabel("Dodatki za CallCenter.", 165, 240, 250, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab15OK = GUICtrlCreateButton("CC Dodatki", 30, 235, 120, 25)
    GUICtrlCreateLabel("OpenVPN klient.", 165, 285, 250, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab16OK = GUICtrlCreateButton("OpenVPN klient", 30, 280, 120, 25)
    GUICtrlCreateLabel("NOD32 Antivirus.", 165, 330, 250, 25)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetColor(-1,0x525252)
    $tab17OK = GUICtrlCreateButton("NOD32 Antivirus", 30, 325, 120, 25)
    
    $_CANCEL = GUICtrlCreateButton("Close the application", 500, 500, 500, 500)
    
    GUISetState()
    
    
While 1

    $Msg = GUIGetMsg()
   
; Software Install
    If $Msg = $tab11OK Then
            
            ProgressOn("Progress Meter", "", "0 percent")
            InstallFont("\\domain.local\Software\_Install\_Default\1\CORPORATE FONT\*.*")

            Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")
            Local Const $HWND_BROADCAST = 0xFFFF
            Local Const $WM_FONTCHANGE = 0x1D
   
            If $sFontsPath = "" Then $sFontsPath = @WindowsDir & "\fonts"
   
            Local $sFontName = StringRegExpReplace($sSourceFile, "^.*\\", "")
            If Not FileCopy($sSourceFile, $sFontsPath & "\" & $sFontName, 1) Then Return SetError(1, 0, 0)
   
            Local $hSearch = FileFindFirstFile($sSourceFile)
            Local $iFontIsWildcard = StringRegExp($sFontName, "\*|\?")
            Local $aRet, $hGdi32_DllOpen = DllOpen("gdi32.dll")
   
            If $hSearch = -1 Then Return SetError(2, 0, 0)
            If $hGdi32_DllOpen = -1 Then Return SetError(3, 0, 0)
   
            While 1
            $sFontName = FileFindNextFile($hSearch)
            If @error Then ExitLoop
       
            If $iFontIsWildcard Then $sFontDescript = StringRegExpReplace($sFontName, "\.[^\.]*$", "")
       
            $aRet = DllCall($hGdi32_DllOpen, "Int", "AddFontResource", "str", $sFontsPath & "\" & $sFontName)
            If IsArray($aRet) And $aRet[0] > 0 Then
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", _
                $sFontDescript, "REG_SZ", $sFontsPath & "\" & $sFontName)
            EndIf
            WEnd
   
            DllClose($hGdi32_DllOpen)
            DllCall("user32.dll", "Int", "SendMessage", "hwnd", $HWND_BROADCAST, "int", $WM_FONTCHANGE, "int", 0, "int", 0)
            Return 1
            EndFunc
            ProgressSet( Round(1/12*100,0), Round(1/12*100,0) & " percent")
            RunWait("msiexec /i \\domain.local\Software\_Install\_Default\1\install_flash_player_active_x.msi /quiet", '', @SW_HIDE)
            ProgressSet( Round(2/12*100,0), Round(2/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\dotnetfx35.exe /passive")
            RunWait('\\domain.local\Software\_Install\_Default\1\cdbxp_setup_4.2.2.984.exe /VERYSILENT /SP- /NORESTART /DIR="C:\Program Files\CDBurnerXP" /GROUP="CDBurnerXP" /MERGETASKS="!desktopicon /nmsaccess"')
            RunWait("C:\Program Files\CDBurnerXP\NMSAccessU.exe -install")
            RunWait("\\domain.local\Software\_Install\_Default\1\AdbeRdr90_en_US.exe /sAll /rps /rs", '', @SW_HIDE)
            ProgressSet( Round(3/12*100,0), Round(3/12/7*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\quicktimealt260.exe /VERYSILENT /COMPONENTS=qt,qt\codec,qt\directshow,qt\plugins,qt\browser /f", '', @SW_HIDE)
            ProgressSet( Round(4/12*100,0), Round(4/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\realalt180.exe /VERYSILENT /COMPONENTS=real,real\codec,real\directshow,real\browser /f", '', @SW_HIDE)
            ProgressSet( Round(5/12*100,0), Round(5/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\Firefox Setup 3.0.exe -ms", '', @SW_HIDE)
            ProgressSet( Round(6/12*100,0), Round(6/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\converter\setup.exe", '', @SW_HIDE)
            ProgressSet( Round(7/12*100,0), Round(7/12*100,0) & " percent")
            RunWait('\\domain.local\Software\_Install\_Default\1\iview410_setup.exe /silent /folder="C:\program files\IrfanView" /desktop=1 /thumbs=1 /group=1 /alluser=1 /assoc=1 /assocallusers', '', @SW_HIDE)
            ProgressSet( Round(8/12*100,0), Round(8/12*100,0) & " percent")
            RunWait('\\domain.local\Software\_Install\_Default\1\7z457.exe /S /D="c:\program files\7 zip"', '', @SW_HIDE)
            ProgressSet( Round(9/12*100,0), Round(9/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\install_flash_player.exe /silent", '', @SW_HIDE)
            ProgressSet( Round(10/12*100,0), Round(10/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\smplayer_0.6.1_setup.exe /silent", '', @SW_HIDE)
            ProgressSet( Round(11/12*100,0), Round(11/12*100,0) & " percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\CuteWriter.exe /silent", '', @SW_HIDE)
            ProgressSet( Round(12/12*100,0), Round(12/12*100,0) & " percent")
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()
            WinWaitActive("")
                        
    EndIf
    
; Navision + IMS Communication
    If $Msg = $tab12OK  Then
        
            ProgressOn("Progress Meter", "", "0 percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\Navision\ClientSP3\CD1\Client\setup.exe /S")
            ProgressSet( Round(1/3*100,0), Round(1/3*100,0) & " percent")
            FileCopy("\\domain.local\Software\_Install\_Default\1\Navision\IMSCommunication\NPSXMLRPCLibrary.dll","C:\Windows")
            ProgressSet( Round(2/3*100,0), Round(2/3*100,0) & " percent")
            RunWait("regsvr32 /s c:\windows\NPSXMLRPCLibrary.dll")
            ProgressSet( Round(3/3*100,0), Round(3/3*100,0) & " percent")
            FileCopy("\\domain.local\Software\_Install\_Default\1\Navision.lnk","C:\Documents and settings\All Users\Desktop")
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()
    EndIf
    
    
; CustomerCenter
    If $Msg = $tab13OK  Then
        
            ShellExecuteWait("\\domain.local\Software\_Install\_Default\1\CustomerCenter_en.jnlp")
            FileCopy("\\domain.local\Software\_Install\_Default\1\CustomerCenter_en.jnlp","C:\Documents and settings\All Users\Desktop")
            
    EndIf


; Avaya Software + Wallboard
    If $Msg = $tab14OK  Then
            RunWait("\\domain.local\Software\_Install\_Default\1\AICinstall\AgentInstaller\AgentInstaller.exe")
            DirCreate("C:\Program Files\Avaya\IC71\bin\Custom_TUS")
            DirCreate("C:\AvayaTemp")
            FileCopy("\\domain.local\Software\_Install\_Default\1\AICinstall\IC712patches\IC712winAgentClient\*.*", "C:\AvayaTemp")
            RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce","AvayaTemp","REG_SZ","C:\AvayaTemp\setupwin32.exe")
            ProgressOn("Progress Meter", "", "0 percent")
            FileCopy("\\domain.local\Software\_Install\_Default\1\AvayaAddon\myhangup.ocx", "C:\Program Files\Avaya\IC71\bin\Custom_TUS")
            RunWait('regsvr32 /s "C:\Program Files\Avaya\IC71\bin\Custom_TUS\MyHangUp.ocx"')
            FileCopy("\\domain.local\Software\_Install\_Default\1\AvayaAddon\avayalogo.gif", "C:\Program Files\Avaya\IC71\bin")
            FileCopy("\\domain.local\Software\_Install\_Default\1\AvayaAddon\Vtel.ini", "C:\Program Files\Avaya\IC71\bin")
            FileCopy("\\domain.local\Software\_Install\_Default\1\AvayaAddon\vesp.imp", "C:\Program Files\Avaya\IC71\etc")
            ProgressSet( Round(1/2*100,0), Round(1/2*100,0) & " percent")
            RunWait('CACLS "c:\program files\avaya" /E /T /C /G "Users":F', '',@sw_hide)
            ProgressSet( Round(2/2*100,0), Round(2/2*100,0) & " percent")
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()
            ShellExecuteWait("\\domain.local\Software\_Install\_Default\1\Marquee.msi")
    EndIf


; CallCenter Requirements
    If $Msg = $tab15OK  Then
        
            RunWait("net localgroup administrators domain\GSCallCenterAdmin /add")
            RunWait("\\domain.local\Software\_Install\_Default\1\Install_Messenger.exe")
            RunWait("\\domain.local\Software\_Install\_Default\1\MSGPluslive-423.exe")
            
        EndIf

; OpenVPN Install
    If $Msg = $tab16OK  Then
        
            DIM $USER
            $USER=InputBox ( "User", "Vpii uporabniko ime:")
            ProgressOn("Progress Meter", "", "0 percent")
            RunWait("\\domain.local\Software\_Install\_Default\1\openvpn-2.0.9-gui-1.0.3-install.exe /S")
            ProgressSet( Round(1/3*100,0), Round(1/3*100,0) & " percent")
            RunWait('net localgroup "Network Configuration Operators" domain\' & $USER & ' /add', '', @SW_HIDE)
            DirCreate('C:\Documents and settings\' & $USER & '\Application Data\OpenVPN')
            DirCreate('C:\Documents and settings\' & $USER & '\Application Data\OpenVPN\Log')
            ProgressSet( Round(2/3*100,0), Round(2/3*100,0) & " percent")
            FileCopy('\\domain.local\Software\_Install\_Default\1\Shortcut to OpenVPN.lnk','C:\Documents and settings\' & $USER & '\Desktop')
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN","config_dir","REG_SZ","%userprofile%\Application Data\OpenVPN")
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN","log_dir","REG_SZ","%userprofile%\Application Data\OpenVPN\log")
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI","config_dir","REG_SZ","%userprofile%\Application Data\OpenVPN")
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\OpenVPN-GUI","log_dir","REG_SZ","%userprofile%\Application Data\OpenVPN\log")
            ProgressSet( Round(3/3*100,0), Round(3/3*100,0) & " percent")
            RunWait("sc config OpenVPNService start= auto", '', @SW_HIDE)
            RunWait("sc start OpenVPNService", '', @SW_HIDE)
            ProgressSet(100 , "Done", "Complete")
            ProgressOff()
            
    EndIf
        
; NOD32
    If $Msg = $tab17OK  Then
        
            RunWait("\\domain.local\Software\_Install\_Default\1\NOD32_2.7_2k-xp-ndntenst.exe")
                        
        EndIf

 
   If $Msg = $_CANCEL Or $Msg = $GUI_EVENT_CLOSE Then
       Exit
   EndIf
    
    
WEnd

Share this post


Link to post
Share on other sites



I would think, and this is just personal preference, that if you are going to do most of your commands based on what the GUI is doing, that you should use CASE syntax instead.

Example:

Let's say i have a 'Button1' and a 'Button2' and maybe even a list box that I want things to do commands on. Instead of using tons of IF/Then statements (which are rather slow), we can switch the values into memory and take needed action:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $button1
        ;- do whatever $button1 is supolsed to do
            
        Case $button2
        ;- do whatever $button2 is supolsed to do
            
        Case $list
        ;- do whatever $list is suposed to do
            
        Case Else
        ;- do whatever else needs to be done if none of the above cases are processed
        ;- this is useful, for example, if you want to run a check command, or verification command
        ;- or check if the window is doing this or that, etc.
        ;- I use Case Else in one of my chat scripts to monitor incomming IRC commands while the primary
        ;- handler (all the cases) are functions which get monitored based on text within the data stream.
    EndSwitch
WEnd

IMHO, if you are talking about speeding up the processing of your script, etc, that would be step #1.

IMHO, step #2, may further speed up your script by moving most of your 'processes' into functions. The reason for this is that you will be able to process your functions, and go back to waiting for command interactions faster than including your functions within the actual command interaction routines.

So, for your various $msg states, just create some functions that relate to it. Secondly, I see tons of 'run' commands in your script. Perhaps consider condensing some of those repetitive functions into a standard function and calling them, this way, you are only calling the process so many times instead of constantly.

Just some random ideas.


-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

If both of you would just use the SciTE syntax check, you would find errors... this script shouldn't even work

While 1

    $Msg = GUIGetMsg()
   
; Software Install
    If $Msg = $tab11OK Then
            
            ProgressOn("Progress Meter", "", "0 percent")
            InstallFont("\\domain.local\Software\_Install\_Default\1\CORPORATE FONT\*.*")

            Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")
            Local Const $HWND_BROADCAST = 0xFFFF
...

there is a function inside a loop that, that cant be correct, I did not run the script

NEXT I would use Tidy ( its in the tool drop-down menu) to clean-up the script

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

Another thing would be to loop the creation of the buttons and labels since they all use the same settings but that would only improve readability and filesize and may be overkill at this moment, but is not very hard to do, read about For-, While- and Do-loops in the helpfile.

And use either Switch or one big If as zackrspv noted, running multiple If's for the same question is not good at all

Share this post


Link to post
Share on other sites

If both of you would just use the SciTE syntax check, you would find errors... this script shouldn't even work

While 1

    $Msg = GUIGetMsg()
   
; Software Install
    If $Msg = $tab11OK Then
            
            ProgressOn("Progress Meter", "", "0 percent")
            InstallFont("\\domain.local\Software\_Install\_Default\1\CORPORATE FONT\*.*")

            Func InstallFont($sSourceFile, $sFontDescript="", $sFontsPath="")
            Local Const $HWND_BROADCAST = 0xFFFF
...

there is a function inside a loop that, that cant be correct, I did not run the script

NEXT I would use Tidy ( its in the tool drop-down menu) to clean-up the script

8)

I do not usually run scripts where people ask to optimize them >_< I just looked at basic structure and gave recommendations. If i was proof-reading his scripts for errors, that'd be a different story :)

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Share this post


Link to post
Share on other sites

and...

$intWindowWidth = 600 ;Round(600, 0)
$intWindowHeight = 440; Round(440, 0)

$My_pic = @TempDir & "\image.jpg"
FileInstall('\\domain.local\Software\_Install\_Default\1\image.jpg', $My_pic)

$objWindow = GUICreate("Installer...", $intWindowWidth, $intWindowHeight)
; GUISetState()

GUICtrlCreatePic($My_pic, 0, 0, 600, 440)
GUICtrlSetState(-1, $GUI_DISABLE)oÝ÷ ÚØ^®§v+'¢ÙÞy×¢|!¢W§ºfÞ®Ëaz·­ëp eIëRµ«^RÇWËZ[hëmêbr'â¶+-êÞ¶§Ê°¢{aj÷­ë2²×¦$x¢¸­¶)}§-¢»a{béh¢hzÉ÷öÖ©¥æ«¶Þ¢÷«ÂäyÖò¶¢~ËZµéÛ!z·ºÚ"µÍÚ[HB ÌÍÓÙÈHÕRQÙ]ÙÊ
BÈÛÙØH[Ý[Y ÌÍÓÙÈH ÌÍÝXLSÒÈ[ÈÈÝY[YÈ]Ú[Û
ÈSTÈÛÛ[][XØ][ÛY   ÌÍÓÙÈH ÌÍÝXLÒÈ[ÈÈÝY[YÈÝÝÛYÙ[Y ÌÍÓÙÈH ÌÍÝXLÓÒÈ[ÈÈÝY[YÈ]^XHÛÙØH
ÈØ[ØY    ÌÍÓÙÈH ÌÍÝXMÒÈ[ÈÈÝY[YÈØ[Ù[]Z[Y[ÂY  ÌÍÓÙÈH ÌÍÝXMSÒÈ[ÈÈÝY[YÈÜ[[Ý[Y   ÌÍÓÙÈH ÌÍÝXMÒÈ[ÈÈÝY[YÈÑÌY   ÌÍÓÙÈH ÌÍÝXMÓÒÈ[ÈÈÝY[YY   ÌÍÓÙÈH ÌÍ×ÐÐSÑSÜ    ÌÍÓÙÈH ÌÍÑÕRWÑUSÐÓÔÑH[^][YÑ[

I have more "if's" than this in some of my older progs

however as stated above by others, using case is a good practice

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Thanks for all the input. I've successfuly replaced the IF statements with CASE. Also moved the InstallFont function out of the "While" statement. Ran a syntax check and I get 0 errors and 0 warnings. Script is running nicely >_< I was wondering tho...

zacksprv:

IMHO, step #2, may further speed up your script by moving most of your 'processes' into functions. The reason for this is that you will be able to process your functions, and go back to waiting for command interactions faster than including your functions within the actual command interaction routines.

So, for your various $msg states, just create some functions that relate to it. Secondly, I see tons of 'run' commands in your script. Perhaps consider condensing some of those repetitive functions into a standard function and calling them, this way, you are only calling the process so many times instead of constantly.

Can you give me an example abot the run commands? I don't quite understand what you mean :idiot:

Also, is there a way to put this into somekind of constants or whatever:

\\server.domain.local

\\server

It's because script is running from a network path. If you enter \\server, script actions will fail to work, since it has \\server.domain.local paths and not \\server. I was not able to figure out yet how to solve that? :)

Edited by skysel

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

If you use Scite4AutoIt3 then you may add these lines at top of your script to make your output compiled EXE file smaller:

#AutoIt3Wrapper_run_obfuscator=y
#Obfuscator_parameters=/striponly
Edited by Zedna

Share this post


Link to post
Share on other sites

Thanks for all the input. I've successfuly replaced the IF statements with CASE. Also moved the InstallFont function out of the "While" statement. Ran a syntax check and I get 0 errors and 0 warnings. Script is running nicely >_< I was wondering tho...

Can you give me an example abot the run commands? I don't quite understand what you mean :idiot:

Also, is there a way to put this into somekind of constants or whatever:

\\server.domain.local

\\server

It's because script is running from a network path. If you enter \\server, script actions will fail to work, since it has \\server.domain.local paths and not \\server. I was not able to figure out yet how to solve that? :)

^^ bump ... :P

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0