Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: delete winbatch script after use
The file is not actually moved until the operating system is restarted. This can be useful for replacing system files. Under Windows 95, and in the 16-bit version, this function performs a regular (non-delayed) FileMove.
More information on WININIT is available from:
http://www.microsoft.com/msdn/sdk/inetsdk/help/itt/wininet/functions/general.htm#wininet_functionsOne method is to have:
thisfile = filefullname(winexename("")) windir = StrCat(DirWindows(0),"wininit.ini") hnd = FileOpen(windir, "APPEND") ; in case exists line = StrCat ("NUL=",thisfile) FileWrite(hnd, line) FileClose(hnd)The file will be deleted on the next startup of the computer.
If the WININIT.INI file already exists, the above code will work, but if it does not exist, then
[rename]ought to be the first line in the file (see below).
Note that the WININIT.INI file is NOT an INI file (be careful) and as such cannot be reliably written to via the iniwritepvt function.
If you create a file called WININIT.INI in the Windows directory, files listed will be renamed during bootup. (If you look at the WININIT.INI and .BAK files in your Windows directory you can figure out how this works.)
An example WININIT.INI file would be:
[rename] C:\Fred\Fault.exe=C:\Fred\Fault.1to delete a file use:
[rename] NULL=C:\Fred\Fault.exeNote: I believe the syntax is destination = source. Looks kind of backwards. Also, this doesn't support long file names.
; create a temporary batch file hnd = FileOpen("c:\temp\wbtest\temp.bat", "WRITE") FileWrite(hnd, "@echo off") FileWrite(hnd, "for %%f in (1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) do dir >nul") ; above line si a dos-only time-waster to allow for the winbatch exe to complete FileWrite(hnd, "del test14.exe") FileWrite(hnd, "del temp.bat") FileClose(hnd) fs = filesize("temp.bat") bin = binaryalloc(fs) binaryread(bin,"c:\temp\wbtest\temp.bat") binaryeodset(bin,fs-2) binarywrite(bin, "c:\temp\wbtest\temp.bat") ; note: binary functions not tested. The idea is to delete the last CRLF from temp.bat ; may be better done with in one swoop with binaryPokeStr instead of filewrite statements dirchange("c:\temp\wbtest") ; or put in the path in the del statements above Run("command.com", "/c c:\temp\wbtest\temp.bat") exit ; this line should go RIGHT after the call to the batch fileI have tried the above except for the binary statements (having manually created the temp.bat file) and it successfully deletes both itself and the winbatch exe file, and closes the Dos box.
Article ID: W13261
Filename: WININIT and Moving or Deleting Files that are in Use.txt
File Created: 2001:01:26:13:59:34
Last Updated: 2001:01:26:13:59:34