programer Posted March 23, 2011 Posted March 23, 2011 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.
am632 Posted March 23, 2011 Posted March 23, 2011 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.
saywell Posted March 23, 2011 Posted March 23, 2011 when u close your program the exe is automatically deleted afterwardsNot 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
am632 Posted March 23, 2011 Posted March 23, 2011 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
AdamUL Posted March 23, 2011 Posted March 23, 2011 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) EndFuncAdam
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now