2012/10/30

autoit auto update example

 
If $Cmdline[0] And $Cmdline[1] = "-s" Then
    ProgressOn($head, "Install in progress", "10 percent")
    ProgressSet( 10, "10 percent")
    Call("Install")
    ProgressSet(100 , "Done", "Complete")
    sleep(1000)
    ProgressOff()
    Exit
EndIf
 
Call("Update")
Call("Install")
 
Func Update()
    ;Check for update on the network
    If StringInStr(@IPAddress1,"192.168")=1 And Ping("192.168.1.1",1000)>=1 Then
        $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
        $FileTimeNew=FileGetTime ( "\\server\share\myprog.exe", 0, 1)
        $FileTimeOld=FileGetTime ( $path&"\myprog.exe", 0, 1)
        If $FileTimeNew<>0 And $FileTimeNew > $FileTimeOld Then; connected to the network and have a newer version
            MsgBox(0,$head&" Update", "A newer version has been detected and will be installed." & _
            @CRLF & "Please wait until the end of the installation and restart again!")
            Run("\\server\share\myprog.exe -s")
            Exit
        EndIf
    EndIf
EndFunc
 
Func Install()
    ;Install (copy) the program in
    $path=@ProgramFilesDir&"\myprog\"; ..\program files\myprog\
    $pathstart=@ProgramsCommonDir&"\myprog\"; ..\All Users\start menu\program\myprog\
    FileCopy ( @ScriptFullPath, $path , 9)
    FileCreateShortcut ( $path&"myprog.exe", $path&"myprog")
    DirCreate($pathstart)
    FileCreateShortcut ( $path&"myprog.exe", $pathstart&"myprog")
    DirCreate ( @AppDataDir&"\myprog\" )
EndFunc
 

沒有留言:

張貼留言