Diar33 Posted June 21, 2005 Share Posted June 21, 2005 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 More sharing options...
Nilfred Posted June 21, 2005 Share Posted June 21, 2005 Main .bat:@ECHO OFFcopy /Y /b date.txt change.bat>nul:DATE /T>>change.batDATE 01/01/2001ECHO The date is now:DATE /TREM Your questionable stuff hereREM Change date backCALL change.batECHO The date is now:DATE /TAuxiliary date.txt:@echo OFFDATENote that date.txt ends with a space and NO Enter at the end of last line. Link to comment Share on other sites More sharing options...
Dumpy Dooby Posted June 21, 2005 Share Posted June 21, 2005 I use the following two files:changedate.bat@echo offSETLOCAL::dafault fileset file=::default dateset Fakedate=if %1a==a goto defaultset file=%1if %2a==a goto defaultset Fakedate=%2 :defaultSET today=%date:~4,10%date=%Fakedate%clsecho.echo: Today is %today%echo.echo: Date changed to %Fakedate%start runit %file%echo.echo: Running %file%SLEEP for 00:00:10echo.date=%today% ::restore previous dateecho: Date changed back to %today%ENDLOCAL:EOFexitrunit.batCMDOW @ /HID@echo offSETLOCAL%1ENDLOCALexitThen I change my shortcuts to point to:changedate "%ProgramFiles%\SomeCompany\SomeProgram\Program.exe" 6/17/05The 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 More sharing options...
Diar33 Posted June 21, 2005 Author Share Posted June 21, 2005 Thank you very much guys, I'm sure I'll be able to get one of these to work for me. I'll be sure to post when everything works the way I want it.Thanks again, Travis Link to comment Share on other sites More sharing options...
Dumpy Dooby Posted June 25, 2005 Share Posted June 25, 2005 Followup? Everything work out okay? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now