Sign in to follow this  
Followers 0
kiman

how to compile multiple files into one exe

12 posts in this topic

I'm uncertain how to include an executable file, such as ad-aware, AND the definition file, all to be compiled into one executable. I'll post the script that I'm using to install from the script directory. I have another script for spybot that includes the exe in the script executable, but I would also like to add the includes updater file to the script's exe. Any help is greatly appreciated! Here's what I'm using:

Adaware:

RunWait(@ScriptDir & "\aawsepersonal.exe" & ' /s /v /qn')
Sleep(200)
_CopyDirWithProgress(@ScriptDir & "\defs\", "C:\Program Files\Lavasoft\Ad-Aware SE Personal\")
Sleep(200)

;-------------------------------------------------------------------------------------------

RunWait("C:\Program Files\Lavasoft\Ad-Aware SE Personal\Ad-Aware.exe")
Sleep(200)

;-------------------------------------------------------------------------------------------
Func _CopyDirWithProgress($sOriginalDir, $sDestDir)
 ;$sOriginalDir and $sDestDir are quite selfexplanatory...
 ;This func returns:
 ; -1 in case of critical error, bad original or destination dir
 ;  0 if everything went all right
 ; >0 is the number of file not copied and it makes a log file
 ;  if in the log appear as error message '0 file copied' it is a bug of some windows' copy command that does not redirect output... 
   
   If StringRight($sOriginalDir, 1) <> '\' Then $sOriginalDir = $sOriginalDir & '\'
   If StringRight($sDestDir, 1) <> '\' Then $sDestDir = $sDestDir & '\'
   If $sOriginalDir = $sDestDir Then Return -1
   
   ProgressOn('Copying...', 'Making list of files...' & @LF & @LF, '', -1, -1, 18)
   Local $aFileList = _FileSearch($sOriginalDir)
   If $aFileList[0] = 0 Then
      ProgressOff()
      SetError(1)
      Return -1
   EndIf
   
   If FileExists($sDestDir) Then
      If Not StringInStr(FileGetAttrib($sDestDir), 'd') Then
         ProgressOff()
         SetError(2)
         Return -1
      EndIf
   Else
      DirCreate($sDestDir)
      If Not FileExists($sDestDir) Then
         ProgressOff()
         SetError(2)
         Return -1
      EndIf
   EndIf
   
   Local $iDirSize, $iCopiedSize = 0, $fProgress = 0
   Local $c, $FileName, $iOutPut = 0, $sLost = '', $sError
   Local $Sl = StringLen($sOriginalDir)
  
   _Quick_Sort($aFileList, 1, $aFileList[0])
   
   $iDirSize = Int(DirGetSize($sOriginalDir) / 1024)

   ProgressSet(Int($fProgress * 100), $aFileList[$c], 'Coping file:')
   For $c = 1 To $aFileList[0]
      $FileName = StringTrimLeft($aFileList[$c], $Sl)
      ProgressSet(Int($fProgress * 100), $aFileList[$c] & ' -> '& $sDestDir & $FileName & @LF & 'Total KiB: ' & $iDirSize & @LF & 'Done KiB: ' & $iCopiedSize, 'Coping file:  ' & Round($fProgress * 100, 2) & ' %   ' & $c & '/' &$aFileList[0])
      
      If StringInStr(FileGetAttrib($aFileList[$c]), 'd') Then
         DirCreate($sDestDir & $FileName)
      Else
         If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then
            If Not FileCopy($aFileList[$c], $sDestDir & $FileName, 1) Then;Tries a second time
               If RunWait(@ComSpec & ' /c copy /y "' & $aFileList[$c] & '" "' & $sDestDir & $FileName & '">' & @TempDir & '\o.tmp', '', @SW_HIDE)=1 Then;and a third time, but this time it takes the error message
                  $sError = FileReadLine(@TempDir & '\o.tmp',1)
                  $iOutPut = $iOutPut + 1
                  $sLost = $sLost & $aFileList[$c] & '  ' & $sError & @CRLF
               EndIf
               FileDelete(@TempDir & '\o.tmp')
            EndIf
         EndIf
         
         FileSetAttrib($sDestDir & $FileName, "+A-RSH");<- Comment this line if you do not want attribs reset.
         
         $iCopiedSize = $iCopiedSize + Int(FileGetSize($aFileList[$c]) / 1024)
         $fProgress = $iCopiedSize / $iDirSize
      EndIf
   Next
  
   ProgressOff()
   
   If $sLost <> '' Then;tries to write the log somewhere.
      If FileWrite($sDestDir & 'notcopied.txt',$sLost) = 0 Then
         If FileWrite($sOriginalDir & 'notcopied.txt',$sLost) = 0 Then
            FileWrite(@WorkingDir & '\notcopied.txt',$sLost)
         EndIf
      EndIf
   EndIf
   
   Return $iOutPut
EndFunc ;==>_CopyDirWithProgress

Func _FileSearch($sIstr, $bSF = 1)
 ; $bSF = 1 means looking in subfolders
 ; $sSF = 0 means looking only in the current folder.
 ; An array is returned with the full path of all files found. The pos [0] keeps the number of elements.
   Local $sIstr, $bSF, $sCriteria, $sBuffer, $iH, $iH2, $sCS, $sCF, $sCF2, $sCP, $sFP, $sOutPut = '', $aNull[1]
   $sCP = StringLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCP = '' Then $sCP = @WorkingDir & '\'
   $sCriteria = StringTrimLeft($sIstr, StringInStr($sIstr, '\', 0, -1))
   If $sCriteria = '' Then $sCriteria = '*.*'
   
 ;To begin we seek in the starting path.
   $sCS = FileFindFirstFile($sCP & $sCriteria)
   If $sCS <> - 1 Then
      Do
         $sCF = FileFindNextFile($sCS)
         If @error Then
            FileClose($sCS)
            ExitLoop
         EndIf
         If $sCF = '.' Or $sCF = '..' Then ContinueLoop
         $sOutPut = $sOutPut & $sCP & $sCF & @LF
      Until 0
   EndIf
   
 ;And after, if needed, in the rest of the folders.
   If $bSF = 1 Then
      $sBuffer = @CR & $sCP & '*' & @LF;The buffer is set for keeping the given path plus a *.
      Do
         $sCS = StringTrimLeft(StringLeft($sBuffer, StringInStr($sBuffer, @LF, 0, 1) - 1), 1);current search.
         $sCP = StringLeft($sCS, StringInStr($sCS, '\', 0, -1));Current search path.
         $iH = FileFindFirstFile($sCS)
         If $iH <> - 1 Then
            Do
               $sCF = FileFindNextFile($iH)
               If @error Then
                  FileClose($iH)
                  ExitLoop
               EndIf
               If $sCF = '.' Or $sCF = '..' Then ContinueLoop
               If StringInStr(FileGetAttrib($sCP & $sCF), 'd') Then
                  $sBuffer = @CR & $sCP & $sCF & '\*' & @LF & $sBuffer;Every folder found is added in the begin of buffer
                  $sFP = $sCP & $sCF & '\';                            for future searches
                  $iH2 = FileFindFirstFile($sFP & $sCriteria);       and checked with the criteria.
                  If $iH2 <> - 1 Then
                     Do
                        $sCF2 = FileFindNextFile($iH2)
                        If @error Then
                           FileClose($iH2)
                           ExitLoop
                        EndIf
                        If $sCF2 = '.' Or $sCF2 = '..' Then ContinueLoop
                        $sOutPut = $sOutPut & $sFP & $sCF2 & @LF;Found items are put in the Output.
                     Until 0
                  EndIf
               EndIf
            Until 0
         EndIf
         $sBuffer = StringReplace($sBuffer, @CR & $sCS & @LF, '')
      Until $sBuffer = ''
   EndIf
   
   If $sOutPut = '' Then
      $aNull[0] = 0
      Return $aNull
   Else
      Return StringSplit(StringTrimRight($sOutPut, 1), @LF)
   EndIf
EndFunc ;==>_FileSearch

Func _Quick_Sort(ByRef $SortArray, $First, $Last);Larry's code
   Dim $Low, $High
   Dim $Temp, $List_Separator
   
   $Low = $First
   $High = $Last
   $List_Separator = StringLen($SortArray[ ($First + $Last) / 2])
   Do
      While (StringLen($SortArray[$Low]) < $List_Separator)
         $Low = $Low + 1
      WEnd
      While (StringLen($SortArray[$High]) > $List_Separator)
         $High = $High - 1
      WEnd
      If ($Low <= $High) Then
         $Temp = $SortArray[$Low]
         $SortArray[$Low] = $SortArray[$High]
         $SortArray[$High] = $Temp
         $Low = $Low + 1
         $High = $High - 1
      EndIf
   Until $Low > $High
   If ($First < $High) Then _Quick_Sort($SortArray, $First, $High)
   If ($Low < $Last) Then _Quick_Sort($SortArray, $Low, $Last)
EndFunc ;==>_Quick_Sort

Spybot:

Global Const $ProgramName = 'Spybot - Search & Destroy' 
Global $Program = @ProgramFilesDir & '\' & $ProgramName & '\' & 'SpybotSD.exe' 
Main()
Exit

Func Main()
    If Not @Compiled Then
        Opt ("TrayIconDebug", 1)
    EndIf
    If Not FileExists($Program) Then
        InstallSpybot()
    EndIf
    RunSpybot()
EndFunc ;==>Main

Func InstallSpybot()
    Local $TempInstall = TempFile('.exe')
    Local $DesktopIcon = @DesktopDir & '\' & $ProgramName & '.lnk' 
    
    TrayTip(@ScriptName, 'Installing Application 1', 1)
    FileInstall("spybotsd14.exe", $TempInstall)
    RunWait(Quote($TempInstall) & ' /verysilent /nocancel /components="main"')
    Sleep(2000)
    FileDelete($TempInstall)
    If FileExists($DesktopIcon) Then
        FileDelete($DesktopIcon)
    EndIf
    RunUpdate()
    RunSilent()
    TrayTip(@ScriptName, 'Done installing Application 1', 1)
    Sleep(2000)
EndFunc ;==>InstallSpybot

Func RunSpybot()
    TrayTip(@ScriptName, 'Running Application 1', 1)
    RunSilent()
    TrayTip(@ScriptName, 'Done running Application 1', 1)
    Sleep(3000)
EndFunc ;==>RunSpybot

Func RunUpdate()
    Local $TempInstall = TempFile('.exe')
    TrayTip(@ScriptName, 'Done updating Application 1', 1)
    FileInstall("spybotsd_includes.exe", $TempInstall)
    RunWait(Quote($TempInstall))
    Sleep(2000)
    FileDelete($TempInstall)
EndFunc ;==>RunUpdate

Func RunSilent()
    RunWait(Quote($Program) & ' /autocheck /autofix /autoclose /autoimmunize /taskbarhide')
EndFunc ;==>RunSilent

Func TempFile($Ext = 'tmp')
    Local $TempName
    If StringLeft($Ext, 1) <> '.'  Then
        $Ext = '.' & $Ext
    EndIf
    Do
        $TempName = "~" 
        While StringLen($TempName) < 8
            $TempName = $TempName & Chr(Round(Random(97, 122), 0))
        Wend
        $TempName = @TempDir & "\" & $TempName & $Ext
    Until Not FileExists($TempName)
    Return ($TempName)
EndFunc ;==>TempFile

Func Quote($TheString, $QuoteChar = '"')
    Return ($QuoteChar & $TheString & $QuoteChar)
EndFunc ;==>Quote

Share this post


Link to post
Share on other sites



Not exactly sure what your problem is - you have FileInstall in there already, so you know what it does. All you have to do is FileInstall everything you need to include.

Share this post


Link to post
Share on other sites

If your having issues, trying using the full path name to the source file you want to install...


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Not exactly sure what your problem is - you have FileInstall in there already, so you know what it does. All you have to do is FileInstall everything you need to include.

I'm still pretty new at this and most of the scripts that I use are ones already made, or ones that I've modified to do what I need them to do. It's been awhile since I worked with these, and I guess I must have figured out how to include the spybot includes file and forgot about it. The run silent part function wasn't what I was wanting it to do, and mistook that for a hangup somewhere in the code. Sorry about that. If I just use the file install method to include the def.ref file for adaware and combine the two scripts into one, should I be okay?

Sorry again about the confusion. I worked on this quite awhile ago and never was able to get things finished the way I wanted. Thanks for you help!

Share this post


Link to post
Share on other sites

Look up FileInstall in the helpfile, that should help.

You can FileInstall as many files as you need into one main script - all you need is to have a definite file path to each one at the time of compiling, and you're all set.

Share this post


Link to post
Share on other sites

Look up FileInstall in the helpfile, that should help.

You can FileInstall as many files as you need into one main script - all you need is to have a definite file path to each one at the time of compiling, and you're all set.

:geek: Echo :o

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I am having a slight problem with getting the defs.ref file to actually transfer to the directory. It shows the definitions as dec 24, 2005 instead of the new defs. I've tried both variable and static paths for the destination, and checked my defs.ref version, and my system clock, lol. Here's the code for adaware:

Global Const $ProgramName = 'Ad-Aware'
Global Const $ProgramFolder1 = 'Lavasoft'
Global Const $ProgramFolder2 = 'Ad-Aware SE Personal'
Global $ProgramPath = @ProgramFilesDir & '\' & $ProgramFolder1 & '\' & $ProgramFolder2
Global $Program = @ProgramFilesDir & '\' & $ProgramFolder1 & '\' & $ProgramFolder2 & '\' & 'Ad-Aware.exe' 
Main()
Exit

Func Main()
    If Not @Compiled Then
        Opt ("TrayIconDebug", 1)
    EndIf
    If Not FileExists($Program) Then
        InstallAdaware()
    EndIf
EndFunc;==>Main

Func InstallAdaware()
    Local $TempInstall = TempFile('.exe')
    Local $DesktopIcon = @DesktopDir & '\' & $ProgramName & '.lnk' 
    
    TrayTip(@ScriptName, 'Installing Application 1', 1)
    FileInstall("H:\installers\final\aawsepersonal.exe", $TempInstall)
    RunWait(Quote($TempInstall) & ' /s /v /qn')
    Sleep(2000)
    TrayTip(@ScriptName, 'Done installing Application 1', 1)
    RunUpdate()
    TrayTip(@ScriptName, 'Application 1 Finished', 1)
    Sleep(2000)
EndFunc;==>InstallAdaware

Func RunUpdate()
    Local $TempInstall = TempFile('.exe')
    FileInstall("H:\installers\final\defs.ref", "C:\Program Files\Lavasoft\Ad-Aware SE Personal\")
    TrayTip(@ScriptName, 'Done updating Application 1', 1)
    Sleep(2000)
    FileDelete($TempInstall)
EndFunc;==>RunUpdate

Func TempFile($Ext = 'tmp')
    Local $TempName
    If StringLeft($Ext, 1) <> '.'  Then
        $Ext = '.' & $Ext
    EndIf
    Do
        $TempName = "~" 
        While StringLen($TempName) < 8
            $TempName = $TempName & Chr(Round(Random(97, 122), 0))
        Wend
        $TempName = @TempDir & "\" & $TempName & $Ext
    Until Not FileExists($TempName)
    Return ($TempName)
EndFunc;==>TempFile

Func Quote($TheString, $QuoteChar = '"')
    Return ($QuoteChar & $TheString & $QuoteChar)
EndFunc;==>Quote
Edited by kiman

Share this post


Link to post
Share on other sites

Files maintain their original creation/modification timestamps when installed


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Sorry, I'm new to this...

Is the new definition file (2-14-06) overwriting the original definition file from the aawsepersonal.exe installation, but retaining the aawsepersonal.exe's defs.ref timestamp? The file size of the defs.ref in the program directory after my script has run is smaller than the defintion I'm copying over (2-14-06). I'm sure I'm not doing something right, but I've tried variations for a couple hours and am lost at this point. Do I need to set the flag to 1 to resolve the problem? I wasn't sure if there was an error elsewhere in my code or what exactly. I appreciate your help and advice you've given so far!

kiman

Edited by kiman

Share this post


Link to post
Share on other sites

Sorry, I'm new to this...

Is the new definition file (2-14-06) overwriting the original definition file from the aawsepersonal.exe installation, but retaining the aawsepersonal.exe's defs.ref timestamp? The file size of the defs.ref in the program directory after my script has run is smaller than the defintion I'm copying over (2-14-06). I'm sure I'm not doing something right, but I've tried variations for a couple hours and am lost at this point. Do I need to set the flag to 1 to resolve the problem? I wasn't sure if there was an error elsewhere in my code or what exactly. I appreciate your help and advice you've given so far!

kiman

I tried setting the flag to 1 and allowed the new defs.ref file to be used. I saw the note about setting the flag in the help file when I started a few hours ago, but I guess I forgot about it and thought it was more of an issue with my noob coding than anything. Thanks everybody for your help! I can't believe how quickly everyone responds!

kiman

Share this post


Link to post
Share on other sites

the flag is an optional paramater, if your going to keep writing to this same computer in the same file directory under the same name, you'll want to set it to one always so you can over write any existing file with current data.

The creation date of the original file time stamp will not change ... this is when you originally installed it on the 'source file' pc. That's the same time stamp that the new computer(s) will have, unless you delete the old one in the source file, and recreate it so it has todays current time stamp date.

Hope I explained that right, they usually don't let me post after 1:00 am.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

the flag is an optional paramater, if your going to keep writing to this same computer in the same file directory under the same name, you'll want to set it to one always so you can over write any existing file with current data.

The creation date of the original file time stamp will not change ... this is when you originally installed it on the 'source file' pc. That's the same time stamp that the new computer(s) will have, unless you delete the old one in the source file, and recreate it so it has todays current time stamp date.

Hope I explained that right, they usually don't let me post after 1:00 am.

Thanks for your help! It had been a long night for me too...I should have just gone to bed and I probably would have realized my mistake immediately with a little rest, lol.

kiman

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