Tom's Guide | Tom's Hardware | Tom's Games | PC Safety Suite
Is it possible to create a self destructive batch file or even automatically delete all the contents from that batch file after the batch file has finished its job.
Any help would be appreciated.
You can put del at the end of your batch file. It will say that the file is missing, but it will still delete it. Anything after the delete will not be processed.
There's a way to make a batch file self-delete without that message comming up:
@echo off
echo Main batch goes here!
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof][eof] is reperesenting the END-OF-FILE character, which you can get on EDIT.COM by pressing CTRL+P+Z.
Everything after the [eof] is ignored, so if in your batch file you need to exit without self-deleting it, this will NOT work:
@echo off
echo We will exit without self-deleting
goto end
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof]
:endIn order to be able to exit the batch file without self-deleting it, use this:
@echo off
type nul> %TEMP%.\batexit.bat
echo We will exit without self-deleting
%TEMP%.\batexit.bat
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof]Got it?
This information was extracted from Laurcence Soucy's batch FAQ #2.
http://home7.inet.tele.dk/batfiles/-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br
|
DOS won't read any other ... |
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Ads by Google |