Jump to content

Is there a way,how to make application rewrite itself?


 Share

Recommended Posts

Hello,

I undertsand i will be bashed badly for something or noone will reply,but i will try :D

When i have script,compited to exe

c:\x\test.exe

and i want to update it by new version,lets say by function "InetGet"

InetGet("http://boiians.cz/test.exe.org/", "c:\x\test.exe")

is it possible to do this somehow?

Make copliled script file to rewrite itself,so it will run as a "new version" next time you execute it?

i have been wondering for a very long time,so i decided to ask here.

Normally,i update my scripts on remote machines using another program,lets say updater.exe,but i would like to do it with one file only.

Is there a way how to set file permisions or something,to allow this?

How?

If its solved somewhere,please,could you point me there?

Thanks a lot for help

Link to comment
Share on other sites

Hello,

I undertsand i will be bashed badly for something or noone will reply,but i will try :D

When i have script,compited to exe

c:\x\test.exe

and i want to update it by new version,lets say by function "InetGet"

InetGet("http://boiians.cz/test.exe.org/", "c:\x\test.exe")

is it possible to do this somehow?

Make copliled script file to rewrite itself,so it will run as a "new version" next time you execute it?

i have been wondering for a very long time,so i decided to ask here.

Normally,i update my scripts on remote machines using another program,lets say updater.exe,but i would like to do it with one file only.

Is there a way how to set file permisions or something,to allow this?

How?

If its solved somewhere,please,could you point me there?

Thanks a lot for help

1.) Compile new version as Testnew.exe

2.) Rename Test.exe to Testold.exe. Yes, rename is possible.

3.) Rename Testnew.exe to Test.exe.

4.) Restart Test.exe

5.) Delete Testold.exe

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

Link to comment
Share on other sites

1.) Compile new version as Testnew.exe

2.) Rename Test.exe to Testold.exe. Yes, rename is possible.

3.) Rename Testnew.exe to Test.exe.

4.) Restart Test.exe

5.) Delete Testold.exe

do you use some UDF for that "rename" ? filemove does not work for me

for example this,

FileMove("c:\a\test.exe", "c:\a\test2.exe")

does not work if "test.exe" is copiled .exe with only "FileMove("c:\a\test.exe", "c:\a\test2.exe")" in it.

run test.exe and it is trying to rename itself - and it will fail because this process is already running.

I was wondering if there was an solution how to do this,ChrisL pointed good udf that can update that script at reboot,but it still cannot make file rename itself (you use external "application" for that)

Link to comment
Share on other sites

Msgbox(0,"","Start")
_UpdateMe("NewFile.exe")


Func _UpdateMe ($newFile)
    
    Local $sCmdFile, $iDelay=1
    If NOT FileExists(@scriptDir & '\' & $newFile) then Return SetError(1)
    
    FileDelete(@TempDir & "\scratch.bat")
    FileDelete(@ScriptFullPath & ".old")
    
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'Rename "' & @ScriptFullPath & '" "' & @ScriptName & '.old"' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'Rename "' & @ScriptDir & '\' & $newFile & '" "' & @ScriptName & '"' & @CRLF _
            & '"' & @ScriptFullPath & '"' & @CRLF _
            & 'del "' & @ScriptFullPath & '.old"' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
    Exit

EndFunc

Link to comment
Share on other sites

Try my code. It works for me. ;-)

__SingleScript() ; kill previous process
$Time = FileGetTime(@ScriptFullPath, 1, 1)
FileDelete(@ScriptFullPath & ".Old")
FileMove(@ScriptFullPath, @ScriptFullPath & ".Old", 1)
MsgBox(0, 'Remember the creation time', $Time)
While Sleep(1000) ; keep the process alive
WEnd

Func __SingleScript()
    Local $O = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
    Local $OI, $CI = $O.ExecQuery("SELECT * FROM Win32_Process", "WQL", 0x30)
    For $OI In $CI
        If $OI.ProcessId = @AutoItPID Then ContinueLoop
        If $OI.Name = StringTrimRight(@ScriptName, 4) & ".EXE" Then ProcessClose($OI.ProcessId)
        If $OI.Name = "AutoIt3.exe" And StringInStr($OI.CommandLine, StringTrimRight(@ScriptName, 4) & ".au3") Then ProcessClose($OI.ProcessId)
    Next
EndFunc   ;==>__SingleScript

App: Au3toCmd              UDF: _SingleScript()                             

Link to comment
Share on other sites

sorry.. but

filecopy work fine...

in the test.exe:

FileCopy("c:\a\test.exe", "c:\a\test2.exe")

1.) Compile new version as test2.exe

2) exit and run test2.exe

3.) delete Test.exe

4.) copy test2.exe to test.exe

5 ) exit and run test.exe

6.) Delete test2.exe

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...