Jump to content

How to load the entire EXE to memory?


Recommended Posts

Hello,

I´m running a script that is OK if it´s loaded from the hard drive. However, if it´s running from a removable drive and the drive is removed while the script is running, it gets to have a weird behavior.

Is it possible to make the intire EXE file to be loaded to memory at the script start?

thanks.

Link to comment
Share on other sites

Hi, It's not exactly loading it from memory but you could make like a run file which runs the program from the temp folder like...

FileCopy("yourprogram.exe", @TempDir, 1)

RunWait(@TempDir & "\yourprogram.exe")

ProcessWaitClose("yourprogram.exe")
FileDelete(@TempDir & "\yourprogram.exe")

Just add the above code into a new script and substitute 'yourprogram.exe' with the name of your application, then when ever u want to run ur prog from your removable media you run the run file instead, which copies your program to the temp folder and executes it from there, then when u close your program the exe is automatically deleted afterwards.

Link to comment
Share on other sites

when u close your program the exe is automatically deleted afterwards

Not if they pull out the memory stick, it isn't!

You'd need to have a way of detecting the presence of the removable drive and exiting and deleting the temp file application when it occurs.

William

Link to comment
Share on other sites

I'm not sure y it wouldnt work with u, I tried it with an app i made on my memory stick, removed the stick then closed the app, the temp exe was successfully deleted afterwards. Unless i missunderstand u?

thanks

aaron

Link to comment
Share on other sites

This is the same idea as am632, copying and running the compiled script from the @TempDir, but using your existing script.

Add this to the top of your existing script.

If @Compiled And FileGetShortName(@ScriptDir) <> FileGetShortName(@TempDir) Then
    If Not FileCopy(@ScriptFullPath, @TempDir & "\", 1) Then
        MsgBox(16, "ERROR!", "Unable to copy " & @ScriptName & " to " & @CRLF & @TempDir & "\" & @CRLF & @CRLF & "The script is unable to run.")
        Exit
    EndIf
    Run(@TempDir & "\" & @ScriptName, @TempDir) ;Re-run the script.
    Exit
EndIf
OnAutoItExitRegister("_CleanUp")

Add this to the bottom of your existing script.

Func _CleanUp()
    If @Compiled And FileGetShortName(@ScriptDir) = FileGetShortName(@TempDir) Then _SelfDelete(3)
EndFunc

Func _SelfDelete($iDelay = 0)
    Local $sCmdFile
    FileDelete(@TempDir & "\scratch.bat")
    $sCmdFile = 'ping -n ' & $iDelay & '127.0.0.1 > nul' & @CRLF _
            & ':loop' & @CRLF _
            & 'del "' & @ScriptFullPath & '" > nul' & @CRLF _
            & 'if exist "' & @ScriptFullPath & '" goto loop' & @CRLF _
            & 'del ' & @TempDir & '\scratch.bat'
    FileWrite(@TempDir & "\scratch.bat", $sCmdFile)
    Run(@TempDir & "\scratch.bat", @TempDir, @SW_HIDE)
EndFunc

Adam

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...