Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset System date

Status
Not open for further replies.

Smoothas

IS-IT--Management
May 1, 2002
93
GB
Hi,
I'm trying to write a batch file that changes the system date to 01/01/01, runs a program, and once that program has completed, set the system date back.

Now, my batch file creation s a little rusty,but So far I have some up with :-

@echo off
ECHO | DATE /t > C:\CUR-DATE.bat
COLOR 2f
date 01/01/2003
cls
echo Running program.
thefileineedtorun.exe
CALL C:\CUR-DATE.bat
ECHO @SET CUR-DATE=%%4 > C:\CURRENT.BAT
date %CUR-DATE%
SET CUR-DATE=
DEL c:\CUR-DATE.BAT
DEL c:\CURRENT.BAT
exit

But I'm being told that - '21' is not recognized as an internal or external command, operable program or batch file.

Prob a classic schoolboy error, but some help would be great.

Thanks in advance
Smoothas
 
The way I do it is to write a simple basic program that
gets the current date and prints it to a file.
(using call in the bat file)
then set the date wanted
DATE 01-01-2003
then run the program
then call another little basic program to
read the file you created containing todays date and
change it back
 
or simpler, the program can get the date and open a bat file
with DATE plus the current date in it.
then change the date, run the program, then call the other
bat file created by the little program.

bas program keepdate.bas
dt$=date$
open "redate.bat" for output as #1
print #1,"DATE ";dt$
close #1

bat file
call keepdate
date 03/03/2003
call myprog
call redate
 
Thanks for the advise guys.
You advise helped me figure it out.
This seems to do the job Perfectly :-

@echo off
cls
COLOR 2f
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE%
COLOR 2f
echo Setting System date to 01/01/03.....
echo.
date 01/01/2003
echo Launching Program........Please Wait
echo.
progthatiwanttorun.exe
echo Resetting System Date back to Todays Date....Please Wait
date %CURDATE%
echo DONE... Exiting
exit

Thanks again for your help and advise.
Smoothas
 
Hmm i get syntax error when using that (and i remmed
out the color 2f statements and the runmyprogram.exe or whatever just to check the date thing.
 
Syntax error? In a batch file?
Could you clarify what the error message is and where you are seeing it?

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
it doesnt get the date. I copied and pasted directly to
notepad your example then remmed the color statements,
and the programiwanttorun.exe line.

it sets the date to 1/01/2003
then asks for the date (rather than resetting it)
so it's not getting the current date in the FOR ... line
 
Well it isn't my code, but it seems to work fine for me. Try putting a pause in to see whats going on.
Code:
cls
COLOR 2f
FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE%
COLOR 2f
echo Setting System date to 01/01/03.....
echo.
date 01/01/2003
echo Launching Program........Please Wait
echo %date%
echo.
pause
echo Resetting System Date back to Todays Date....Please Wait
date %CURDATE%
echo %date%
pause
echo DONE... Exiting
exit
Save that as time.bat and run it. At the first pause you should see system date as 1/1/2003, second pause should be back to today. Having said that, if you replace the FOR... line with
Code:
SET CURDATE=%DATE%
it still works for me!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
set curdate=%DATE% returns nothing so no syntax error but
current date is not saved.

OS is ME.
 
Sorry I can't test on ME - don't have anything that old! All the above stuff works on XP.

There is some good stuff on the basics of batch files at:

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
i've got an xp right here next to the me machine, just didnt try in on that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top