Change time by one hour

  • Thread starter Thread starter Lost in Microbiology
  • Start date Start date
L

Lost in Microbiology

Hello All,

I tried using the command prompt to change the time by one hour, but
couldn't quite get it to work. What I am looking to do is perform a function
on the current system time. I have a remote computer that has a limited user
account and can't change the clock. I want to create a batch file, burn it to
a disk and let them run that. What I was trying was to add 01:00:00 to the
current time from the command prompt, but I think this is beyond my
abilities. Any help would be greatly appreciated.
 
Lost in Microbiology said:
Hello All,

I tried using the command prompt to change the time by one hour, but
couldn't quite get it to work. What I am looking to do is perform a
function
on the current system time. I have a remote computer that has a limited
user
account and can't change the clock. I want to create a batch file, burn it
to
a disk and let them run that. What I was trying was to add 01:00:00 to the
current time from the command prompt, but I think this is beyond my
abilities. Any help would be greatly appreciated.

As an afterthought: If your users run the command twice then they will
advance the clock by two hours!
 
Pegasus (MVP) said:
You can get them to run this batch file:
@echo off
for /F "delims=:" %%a in ('echo %time%') do set /a hour=%%a + 1
for /F "tokens=2* delims=:" %%a in ('echo %time%') do set
NewTime=%hour%:%%a:%%b
echo Setting the time to %NewTime%
rem time %NewTime%

To test it, run it as it is. To activate it, remove the word "rem" in the
last line.

Note: Do not retype this batch file. Use copy & paste instead.

Thank you for the quick response. In testing I received the error 'New Time'
is not recognized as an internal or external command, and the command prompt
closes.

I just copied it and pasted into notepad, saved it as a .bat file, ALL Files
under file type. Is this just operator error?

THanks
 
Lost in Microbiology said:
Hello All,

I tried using the command prompt to change the time by one hour, but
couldn't quite get it to work. What I am looking to do is perform a
function
on the current system time. I have a remote computer that has a limited
user
account and can't change the clock. I want to create a batch file, burn it
to
a disk and let them run that. What I was trying was to add 01:00:00 to the
current time from the command prompt, but I think this is beyond my
abilities. Any help would be greatly appreciated.

You can get them to run this batch file:
@echo off
for /F "delims=:" %%a in ('echo %time%') do set /a hour=%%a + 1
for /F "tokens=2* delims=:" %%a in ('echo %time%') do set
NewTime=%hour%:%%a:%%b
echo Setting the time to %NewTime%
rem time %NewTime%

To test it, run it as it is. To activate it, remove the word "rem" in the
last line.

Note: Do not retype this batch file. Use copy & paste instead.
 
Lost in Microbiology said:
Thank you for the quick response. In testing I received the error 'New
Time'
is not recognized as an internal or external command, and the command
prompt
closes.

I just copied it and pasted into notepad, saved it as a .bat file, ALL
Files
under file type. Is this just operator error?

THanks

This happens because your newsreader broke up the batch file lines and you
did not "unbreak" them. Here is a line-numbered version of the same batch
file so that you can see clearly where each line starts:
1. @echo off
2. for /F "delims=:" %%a in ('echo %time%') do set /a hour=%%a + 1
3. for /F "tokens=2* delims=:" %%a in ('echo %time%') do set
NewTime=%hour%:%%a:%%b
4. echo Setting the time to %NewTime%
5. echo time %NewTime%
 
Thanks Pegasus, it worked brilliantly!

And yes, my typical user definitely has the ability to double click on the
..bat file about a hundred times to screw it up. Maybe I will go "Mission
Impossible" on them and send a CD that self destructs after one use.

Thanks again, you just improved my day by a factor of 100.
 
Lost in Microbiology said:
Thanks Pegasus, it worked brilliantly!

And yes, my typical user definitely has the ability to double click on the
.bat file about a hundred times to screw it up. Maybe I will go "Mission
Impossible" on them and send a CD that self destructs after one use.

Thanks again, you just improved my day by a factor of 100.

Thanks for the feedback. You can, of course, prevent your user from changing
the time more than once, e.g. like so:

01. @echo off
02. set FlagFile=c:\TimeChange.txt
03. if exist %FlagFile% (
04. echo %UserName% attempted to change the time on %date% at %time% >>
%FlagFile%
05. echo.
06. echo You have already advanced the PC's time. Can't do it twice . . .
07. goto Exit
08. )
09.
10. echo Time changed on %date% at %time% by %UserName% > %FlagFile%
11. for /F "delims=:" %%a in ('echo %time%') do set /a hour=%%a + 1
12. for /F "tokens=2* delims=:" %%a in ('echo %time%') do set
NewTime=%hour%:%%a:%%b
13. echo Setting the PC's time to %NewTime%
14. time %NewTime%
15.
16. :Exit
17. echo.
18. echo Press the Space Bar to close this window.
19. pause > nul
 
Back
Top