Restart a batch file only 5 times

February 1, 2011 at 05:10:30
Specs: Windows 7
HI this is the batch file I am using

@echo off
for /L %%a in (1,1,100) do (
xcopy /d /y /c c:\folder1 c:\folder2\
fc /L C:\folder1\*.* C:\folder2\*.*
del folder2 /Q /F
ping localhost -n 3 > nul
)
shutdown /r /t 01

I would like to keep this in startup and I want that the script should restart the system 5 times only and do its task

Can someone guide me


See More: Restart a batch file only 5 times

Report •


#1
February 1, 2011 at 14:44:57
@echo off
set /p count=<C:\count.txt
if /i %count% == 5 goto :EOF
set /a count=count+1
echo %count% >C:\count.txt
for /L %%a in (1,1,100) do (
xcopy /d /y /c c:\folder1 c:\folder2\
fc /L C:\folder1\*.* C:\folder2\*.*
del folder2 /Q /F
ping localhost -n 3 > nul

)
shutdown /r /t 01

try it..It shoud work.do let us know the outcome

Subhash Chandra.
www.s-chandra.co.cc


Report •

#2
February 1, 2011 at 23:42:01
Hi Subhash,

Firstly Thanx a lot for ur help.
I knew to do it via count but it wud have taken me more time so once again thanx for ur help.

Now this runs perfectly fine, but I have to insert username & password, so is it possible to do that in the code, so tht it accepts username & password automatically for win7 & win2008 r2

Lastly in the last count is it possible to shutdown the system instead of not doing anything.

Your help is much appreciated.
sheetal



Report •

#3
February 2, 2011 at 10:23:47

You Welcome ..

@echo off
set /p count=<C:\count.txt
if /i %count% == 5 shutdown -s -t 30
set /a count=count+1
echo %count% >C:\count.txt
for /L %%a in (1,1,100) do (
xcopy /d /y /c c:\folder1 c:\folder2\
fc /L C:\folder1\*.* C:\folder2\*.*
del folder2 /Q /F
ping localhost -n 3 > nul
)
shutdown /r /t 01


Sure shutdown can be done .. just change GOTO :EOF to shutdown command.

I m not sure what exactly you mean to do by username and password.
What does the username password will do here ?

Subhash Chandra.
www.s-chandra.co.cc


Report •

Related Solutions

#4
February 2, 2011 at 23:34:35
Well I just read what I had written and agreed its difficult to understand my fault.

I have kept the above script in windows start up, so it will restart the system till count 5

But every time the system starts, it asks for user name & password, which I have to give manually for login.

Can this process of auto logging to windows system be incorporated in the above script.

Thanks


Report •

#5
February 3, 2011 at 05:02:16
if its windows xp u can enable auto login..google for enable auto login in xp and u will get lot of article.
sorry..being on phone i cant paste that registry key

Subhash Chandra.
www.s-chandra.co.cc


Report •

#6
February 3, 2011 at 06:52:55
I am in Win 2K8 R2 & windows7, I will check it out

Report •


Ask Question