Posts: 276
Threads: 34
Joined: Dec 2016
Which function to use? so that exe file automat delete after Running successfully ?
I know: End of the batch file, I use the code ( del %0 ) When the batch run is completeļ¼ I can automatically delete the batch file.
but: In the QM code, before the creation of exe, Add what code can be achieved? Thanks in advance,I hope someone can help me find a way !
Posts: 12,073
Threads: 140
Joined: Dec 2002
Exe cannot delete itself directly. The OS does not allow it. Try to launch a .bat or something that deletes it after eg 1 second.
Posts: 276
Threads: 34
Joined: Dec 2016
I used the following code to remove the exe file but did not succeed :oops:
Macro
Macro4
str s=
;Del /f /q %desktop%\Macro4.exe
__TempFile f.Init(".bat" "" "" s)
RunConsole2 f
Posts: 12,073
Threads: 140
Joined: Dec 2002
RunConsole2 waits. Use run, it does not wait. Don't use __TempFile, instead let the .bat delete self.
Posts: 12,073
Threads: 140
Joined: Dec 2002
Macro
Macro2829
mes "macro"
;delete this exe
#if EXE=1
str s=
F
;timeout 2
;del "{ExeFullPath}"
;del %0
str tempFile="$temp$\delete my exe.bat"
s.setfile(tempFile)
run tempFile "" "" "" 16
#endif
Posts: 276
Threads: 34
Joined: Dec 2016
The following code is found in the ahk forum: ahk generated exe, I can automatically delete the exe file, how to use it in Qm?
delself()
{
if (A_IsCompiled)
{
bat=
(LTrim
tart
ping 127.0.0.1 -n 2>nul
del `%1
if exist `%1 goto start
del `%0
)
batfilename=delete.bat
IfExist %batfilename%
FileDelete %batfilename%
FileAppend, %bat%, %batfilename%
Run, %batfilename% "%A_ScriptFullPath%", , Hide
ExitApp
}
}
Posts: 276
Threads: 34
Joined: Dec 2016
Gintaras Wrote:Macro Macro2829
mes "macro"
;delete this exe
#if EXE=1
str s=
F
;timeout 2
;del "{ExeFullPath}"
;del %0
str tempFile="$temp$\delete my exe.bat"
s.setfile(tempFile)
run tempFile "" "" "" 16
#endif
Test success, thank you very much
Posts: 12,073
Threads: 140
Joined: Dec 2002
Note that the timeout command is unavailable on Windows XP. It seems the most reliable workaround is ping, like in the ahk script.
http://stackoverflow.com/questions/1672 ... mpt-or-dos
Posts: 276
Threads: 34
Joined: Dec 2016
Thank you for the reminder that I have replaced the following code:
Macro
Macro7
mes "macro"
;delete this exe
#if EXE=1
str s=
F
;ping 127.0.0.1 -n 2>nul
;del "{ExeFullPath}"
;del %0
str tempFile="$temp$\delete my exe.bat"
s.setfile(tempFile)
run tempFile "" "" "" 16
#endif