Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Credits 2 Posts 2 Joined 2009-09-07 04:00 16-year member UID 151602 Gender Male
Status Offline
Little brother has just started to get in touch with batch processing and wants to write a batch file. I've racked my brains and still can't figure it out. Please help from the experts.
Requirement: Automatically restart 30 seconds after booting. After restarting three times, the fourth time automatically delete its own file.
Credits 2,362 Posts 1,133 Joined 2008-02-02 21:36 18-year member UID 110072 Gender Male
Status Offline
Put it in the startup directory. Automatically run every time it restarts, and redirect a :1 after itself. The batch script reads itself to judge the number of :1. If it reaches 3 times, delete itself.
Demo version Note, don't make a line break at the end, so that it's more convenient for digital calculation~
@echo off
call :count
if %a% lss 3 (set /p=+1>>%0<nul &echo,shutdown -r -t 30) else (echo,del %0)
pause
exit
:count
set /a a=0
[ Last edited by 523066680 on 2009-9-11 at 10:45 ]