Page 1 of 1

Selfmodifying .bat

Posted: 15 Jul 2024 11:52
by miskox
I needed an information when .bat file was run - so I kept this information in a seperate file. But then I thought it would be better to have this information in the .bat file itself as the last line (because there are no other files I need). So this would not be too hard to implement. So here it is:

Code: Select all

@echo off
copy /y %~f0 *.backup 
findstr /B /V /C:"LLLLL#" %~f0 >tmp.tmp&echo LLLLL#Last run was at: %date% %time% %username%#>>tmp.tmp&move tmp.tmp %~f0 >nul
fc %~n0.backup %~f0
goto :EOF

LLLLL#Last run was at: pon. 15. 07. 2024 19:49:23,88 saso#
Differences:

Code: Select all

Comparing files test.backup and C:\TEMP\TEST.CMD
***** test.backup

LLLLL#Last run was at: pon. 15. 07. 2024 19:49:23,88 saso#
***** C:\TEMP\TEST.CMD

LLLLL#Last run was at: pon. 15. 07. 2024 19:50:28,52 saso#
*****
Saso