WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DLLs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Deleting DLL Files after Execution

Keywords: 	 Deleting dll files after execution  cleanup dlls

Question:

When the exe is done executing, at least 2 dlls are left in the same directory as the exe. Is there a way to delete these dlls upon termination. Terminations ends normally every time and if I manually try to delete them before terminating the script I get an error because the dlls are still in use.

Answer:

Add code list this to your script to write a DOS BAT file to delete the files...
del_files_temp = FileCreateTemp("~ww")                            ; get a .tmp file
del_files_path=StrReplace(StrLower(del_files_temp),".tmp",".bat") ; create bat file name
FileRename(del_files_temp,del_files_path)                         ; rename .tmp to .bat file

handle = FileOpen(del_files_path, "WRITE")                        ; open bat file for write

FileWrite(handle, "@ECHO OFF%@CRLF%REM ******THIS FILE IS SAFE TO DELETE******%@CRLF%%@CRLF%ECHO ON")

FileWrite(handle, ":loop")                                        ; delete older dlls (if there) 2004A-
FileWrite(handle, "era wbd*34i.dll")                              ; delete dlls
FileWrite(handle, "era wbo*34i.dll")                              
FileWrite(handle, "if exist wbd*34i.dll goto loop")               ; if file not deleted, loop and try again
FileWrite(handle, "if exist wbo*34i.dll goto loop")

FileWrite(handle, ":loop2")                                       ; delete newer dlls  2004B+
FileWrite(handle, "era wbd*44i.dll")                              ; delete dlls
FileWrite(handle, "era wbo*44i.dll")                              
FileWrite(handle, "if exist wbd*44i.dll goto loop2")               
FileWrite(handle, "if exist wbo*44i.dll goto loop2")              ; if file not deleted, loop and try again

FileWrite(handle, ":loop3")                                       ; delete other files
FileWrite(handle, "era yourfile1.txt")                            ; delete your files
FileWrite(handle, "era yourfile2.txt")                            ; add other files to delete here
FileWrite(handle, "if exist yourfile1.txtl goto loop3")           ; if file not deleted, loop and try again    
FileWrite(handle, "if exist yourfile3 goto loop3")
                                                                  ; delete *this* bat file
FileWrite(handle, StrCat("era ",del_files_path))

FileClose(handle)

RunHide(del_files_path,"")
Exit

Article ID:   W15488
File Created: 2004:03:12:11:58:06
Last Updated: 2004:03:12:11:58:06