« Return to Thread: Cool Windows commandline stuff

RE: Cool Windows commandline stuff

by gavin-egan.com :: Rate this Message:

Reply to Author | View in Thread

I had a problem where some software had run out of date and would run if the
clock was set back a month (the supplier of the software took a couple of
weeks to get new cd's to us)

However there was other software running that required  the date to be
correct
So this little bit of code does the following (all in a batch file)

:: finds the date,
:: changes it back a month,
:: writes a batch file that starts a program,
:: calls the batch file that starts the program required
:: waits a period of time for that program to start (in this case 15 seconds
using ping)
:: gets the new date
:: changes it forward
:: deletes files made by itself
:: Exits

Works well (well at least it did for the two weeks required)

Its probably spagetti code to most good coders - not only this but as I tend
to write things on the fly
Until they work its almost certainly 4x longer than it needs to be.
But it works

Incidentally the Subst command is very useful
I usually write dur.bat and ls.bat both of which just contain dir /o for
most windows systems to save me remembering what system I am on and also to
correct typos

Heres the batch

@ECHO OFF


:: ----- -- DATE CHANGER FOR COCKUP -----
:: ----- -- CREATED BY CHRIS GAVIN-EGAN



ECHO start /B /D "***FOLDER LOCATION OF PROGRAM TO RUN ***" /SEPARATE
/NORMAL  *** Filename.exE >TW3.BAT
ECHO exit >>TW3.BAT

cls

ECHO.
ECHO.
ECHO.
ECHO.
ECHO CHANGING DATE ONE MONTH BACK
ECHO WILL NOW RUN THE PROGRAM
ECHO WHEN FINISHED - HIT RETURN TO RESTORE DATE
ECHO.
ECHO.
echo.

:: BECAUSE THIS RUNS SEQUENTIALLY THERE IS NO NEED TO CHECK FOR SWAPOVER OF
TIME MIDNIGHT

::SET THINGS UP

:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A
for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A
for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B
                               
if %varmonth%==12 set varchanged=11
if %varmonth%==12 goto setback
if %varmonth%==11 set varchanged=10
if %varmonth%==11 goto setback
if %varmonth%==10 set varchanged=09
if %varmonth%==10 goto setback
if %varmonth%==09 set varchanged=08
if %varmonth%==09 goto setback
if %varmonth%==08 set varchanged=07
if %varmonth%==08 goto setback
if %varmonth%==07 set varchanged=06
if %varmonth%==07 goto setback
if %varmonth%==06 set varchanged=05
if %varmonth%==06 goto setback
if %varmonth%==05 set varchanged=04
if %varmonth%==05 goto setback
if %varmonth%==04 set varchanged=03
if %varmonth%==04 goto setback
if %varmonth%==03 set varchanged=02
if %varmonth%==03 goto setback
if %varmonth%==02 set varchanged=01
if %varmonth%==02 goto setback
if %varmonth%==01 set varchanged=12

:setback
date=%vardays%-%varchanged%-%varyear%


::DO STUFF HERE


START TW3.BAT
cls
PING 1.1.1.1 -n 1 -w 15000 >NUL

ECHO.
ECHO.
ECHO.
ECHO.
ECHO PRESS ANOTHER KEY TO
ECHO RESTORE THE DATE
ECHO.
ECHO.
ECHO.
echo.

 


:: GET TODAYS DATE
for /F "tokens=1 delims=/- " %%A in ('date/T') do set varday=%%A
for /F "tokens=2 delims=/- " %%A in ('date/T') do set vardays=%%A
for /F "tokens=3 delims=/- " %%A in ('date/T') do set varmonth=%%A
for /F "tokens=4 delims=/- " %%A in ('date/T') do set varyear=%%A
for /F "tokens=2-4 delims=/- " %%A in ('date/T') do set var=%%C%%A%%B

if %varmonth%==12 set varchanged=01      
if %varmonth%==12 goto setforward
if %varmonth%==11 set varchanged=12      
if %varmonth%==11 goto setforward
if %varmonth%==10 set varchanged=11      
if %varmonth%==10 goto setforward
if %varmonth%==09 set varchanged=10      
if %varmonth%==09 goto setforward
if %varmonth%==08 set varchanged=09      
if %varmonth%==08 goto setforward
if %varmonth%==07 set varchanged=08      
if %varmonth%==07 goto setforward
if %varmonth%==06 set varchanged=07      
if %varmonth%==06 goto setforward
if %varmonth%==05 set varchanged=06      
if %varmonth%==05 goto setforward
if %varmonth%==04 set varchanged=05      
if %varmonth%==04 goto setforward
if %varmonth%==03 set varchanged=04      
if %varmonth%==03 goto setforward
if %varmonth%==02 set varchanged=03      
if %varmonth%==02 goto setforward
if %varmonth%==01 set varchanged=02      
:setforward      
date=%vardays%-%varchanged%-%varyear%
iF EXIST TW3.BAT ERASE TW3.BAT
EXIT



-----Original Message-----
From: piclist-bounces@... [mailto:piclist-bounces@...] On Behalf Of
Tomás Ó hÉilidhe
Sent: Monday, June 23, 2008 8:17 AM
To: Microcontroller discussion list - Public.
Subject: [OT] Cool Windows commandline stuff


I initially took a liking to Linux because you can do *everything* at the
commandline... but recently I've discovered a few cool things you can do
with Windows at the commandline.

For instance, let's say your pissed off with having to navigate to
"C:\Documents and Settings\My Name\My Documents", well just go to the
commandline and type:

    subst x: "C:\Documents and Settings\Whoever\My Documents"

Now x: is a drive that points to the aforementioned directory.

One thing I really like about Linux is the "ifconfig" command. For instance
here's how you'd set your IP address:

    ipconfig eth0 192.168.1.87 netmask 255.255.255.0

Well, under Windows, you can set your IP address and default gateway in one
foul swoop with:

    netsh interface ip set address "eth0" static 192.168.1.87 255.255.255.0
192.168.1.1 1

Does anyone else have some cool Windows commandline stuff to share?

--
http://www.piclist.com PIC/SX FAQ & list archive View/change your membership
options at http://mailman.mit.edu/mailman/listinfo/piclist


--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist

 « Return to Thread: Cool Windows commandline stuff

LightInTheBox - Buy quality products at wholesale price!