Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Make WinBatch Delete itself

 Keywords:  delete EXE DLLs Complete done clean up

Question:

I compiled a winbatch program, I would like to delete it after finish running.

I go this way...

----------------snip-----------
winbatch code here
.....
EXE_PATH = FILEPATH(WINEXENAME(""))
DEL_FILES_PATH = "C:\DELFILES.BAT"
ENTER = @CRLF

HANDLE = FILEOPEN(DEL_FILES_PATH, "WRITE")
FILEWRITE(HANDLE, "@ECHO OFF%ENTER%REM ******THIS FILE IS SAFE
TO DELETE******%ENTER%%ENTER%ECHO ON")
FILEWRITE(HANDLE, STRCAT("DEL /Q ",'"',EXE_PATH,"WW*I.DLL",'"'))
FILEWRITE(HANDLE, STRCAT("DEL /Q ",'"',EXE_PATH,"W*32I.DLL",'"'))
FILEWRITE(HANDLE, STRCAT("DEL /Q ",'"',WINEXENAME(""),'"'))
FILECLOSE(HANDLE)

RUNHIDE(DEL_FILES_PATH,"")
EXIT
--------------end----------
The problem was the EXE and core DLL files can't be deleted
successfully.(File in use)

Any suggestion? Any hits? :-)

Answer:

The WinBatch part seems basically OK.

You need a better BAT file

Something like

:loop
era filea.exe
era fileb.dll
if exist filea.exe goto loop
if exist fileb.dll goto loop
era thisfile.bat
exit
So the BAT file will keep trying until the files are deleted, so it can wait for the Winbatch exe program to properly exit.
Here is some sample code that deletes the WIL dlls that get generated by a compiled EXE.
del_files_path = "C:\DELFILES.BAT"
handle = FileOpen(del_files_path, "WRITE")
FileWrite(handle, "@ECHO OFF%@CRLF%REM ******THIS FILE IS SAFE TO DELETE******%@CRLF%%@CRLF%ECHO ON")
FileWrite(handle, ":loop")
FileWrite(handle, "era wbd*34i.dll")
FileWrite(handle, "era wbo*34i.dll")
FileWrite(handle, "if exist wbd*34i.dll goto loop")
FileWrite(handle, "if exist wbo*34i.dll goto loop")
FileWrite(handle, "era ",DEL_FILES_PATH)
FileClose(handle)
Runhide(del_files_path,"")
Exit

Article ID:   W14857