Jump to content

Batch file help


Diar33

Recommended Posts

Hello,

I'm having some problems writing a batch file that would save the current date (in a text file or variable or anything really), then change the date, call a .exe to install a program, and then restore the true current date. I'm somewhat new to this, but I did a little research on the Date command, and I'm not too sure how to use it in this way.

Thanks in advance,

Travis

Link to comment
Share on other sites


Main .bat:

@ECHO OFF
copy /Y /b date.txt change.bat>nul:
DATE /T>>change.bat
DATE 01/01/2001
ECHO The date is now:
DATE /T
REM Your questionable stuff here
REM Change date back
CALL change.bat
ECHO The date is now:
DATE /T

Auxiliary date.txt:

@echo OFF
DATE

Note that date.txt ends with a space and NO Enter at the end of last line.

Link to comment
Share on other sites

I use the following two files:

changedate.bat

@echo off
SETLOCAL

::dafault file
set file=
::default date
set Fakedate=

if %1a==a goto default
set file=%1
if %2a==a goto default
set Fakedate=%2

:default

SET today=%date:~4,10%
date=%Fakedate%
cls
echo.
echo: Today is %today%
echo.
echo: Date changed to %Fakedate%

start runit %file%
echo.
echo: Running %file%
SLEEP for 00:00:10

echo.
date=%today% ::restore previous date
echo: Date changed back to %today%
ENDLOCAL

:EOF
exit

runit.bat

CMDOW @ /HID
@echo off
SETLOCAL
%1
ENDLOCAL
exit

Then I change my shortcuts to point to:

changedate "%ProgramFiles%\SomeCompany\SomeProgram\Program.exe" 6/17/05

The above would change the date to 6/17/05 (in case you didn't get that).

Now a little explanation of what goes on.

First, changedate.bat gets the current date and stores it as %Today%. Then, it changes the date to %FakeDate% (you specify fakedate in your shortcut. However, if it is not there, then the script will auto-use the date specified on line 7).

After it changes the date, it starts the program (either specified in the command line or on line 5). It sleeps for 10 seconds (You will need to download sleep.exe from somewhere. Just google it.) to give you some time to click "Continue" or whatever.

After sleeping for 10 seconds, it changes the date back to the original date. Note, however, that if you run this script at 11:59:55pm, then when you change the date back, it will be a day behind.

You can choose to change line 24 to the following, and it should wait for the program to close, before changing the date back.

start /wait %file%

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...