| 1. |
Solve : Batch file to change to a specific date? |
|
Answer» I need to write a batch file so I can set the date to start a program, but I then need to change back to the current date after the program has loaded. I've not written any batch files in a long time and can't work out how to do it.This is dependent on your regional and language settings. I need to write a batch file so I can set the date to start a program, Why? Has the trial period EXPIRED? It's a parts catalogue, new one issued every month, no longer got access to latest one so having to use an old one. Quote from: Squashman on January 11, 2012, 07:53:01 AM This is dependent on your regional and language settings. I'm using XP and the date format is wrong, I get today=1/-01- You need to show me how the date variable outputs from the cmd prompt just like I showed you in my first post.It looks like it is likely UK date output, which expands DD/MM/YYYY. Let's modify for that and see if it works out better for the OP. Quote from: Raven19528 on January 11, 2012, 11:47:40 AM It looks like it is likely UK date output I think I once saw the Artilleryman at Horsell Common, near Woking. Quote from: Squashman on January 11, 2012, 10:39:46 AM You need to show me how the date variable outputs from the cmd prompt just like I showed you in my first post. OK I've worked out the first line for saving today's date SET TODAY=%date:~0,2%-%date:~3,2%-%date:~6,4% this gives me 12-01-2012 I'm using C:\myprog\myprog.exe which starts the prog OK, but after loading the prog the batch file stops and only completes after exiting the prog, what I realy need to do is reset the date once the prog has loaded. Line 3 start "" "C:\myprog\myprog.exe" IGNORES the date change.Here is an excerpt from the start /? text that I think specifies the problem: Code: [Select]Microsoft Windows [Version 6.1.7601] When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script. The way around this is to "start" a different command process, which in turn starts the program, but never takes control away from your original batch file. Example: Code: [Select]SET TODAY=%date:~0,2%-%date:~3,2%-%date:~6,4% REM setting date back to an older date DATE 12-11-11 (echo start "" "C:\path to my program\myprogram.exe" echo del ^%^0) >tempstart.bat start "" tempstart.bat REM Changing date back to todays date ping 1.1.1.1 -n 1 -w 2000>nul DATE %TODAY% This may or may not be a long enough delay (2 seconds), but it does institute a slight delay before changing the date back to today. If this isn't required, you can remove the ping line. Quote from: The Artilleryman on January 12, 2012, 10:17:27 AM which starts the prog OK, but after loading the prog the batch file stops and only completes after exiting the prog, what I realy need to do is reset the date once the prog has loaded.I don't throw out random code for my good health. I gave you the correct code for starting the program in my first post. I had no control over the date output as I explained in both of my previous posts because anyone can change the short date format in their regional settings.Hi all This is my elegant solution to solving the date issue Edit launch to read the Progam Just amend the dates 01/01/2012 to whatever date you require Amend c:\...... to the shortcut properties of the program you wish to run When you exit the program the date will rest to today! Just copy and paste into notepad and SAVE as a .bat file ECHO OFF CLS :MENU ECHO. ECHO ....................................... ........ ECHO PRESS 1 to select your task, or 2 to EXIT. ECHO ....................................... ........ ECHO. ECHO 1 - Launch xxxxxxxxxxxx ECHO 2 - Exit ECHO. SET /P M=Type 1, 2, then press ENTER: IF %M%==1 GOTO PROGRAM IF %M%==2 GOTO RESETDATE :PROGRAM FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET CURDATE=%DATE% COLOR 4f echo Setting System date to 01/01/2012 echo. date 01/01/2012 echo Launching Program........Please Wait echo. "c:\xxxxxxxxx.exe" echo Resetting System Date back to Todays Date....Please Wait date %CURDATE% Hope this helps Jules Code: [Select]SET /P M=Type 1, 2, then press ENTER: What will happen if the user TYPES 3 or just presses ENTER? None of the scripts in this thread should be run sufficiently close to midnight that the line with the start command finishes the next day. Nothing! You could delete the first section and just run the program batch file but remember running a date change could corrupt other files you save and will certainly impact your internet browser home page so be careful - hence to 1 or 2 check to make sure. Julian Quote from: jjh281 on February 29, 2012, 01:50:00 PM Nothing! If the user types 3 and presses Enter, neither of the following IF tests will be satisfied, so the script will fall through to :PROGRAM, and if they just press ENTER, then %M% will be set to an empty string, and the script will halt with an error at the first IF test. |
|