AutoHotkey Community

It is currently May 27th, 2012, 12:51 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Atomic Time Sync.
PostPosted: January 20th, 2006, 4:27 am 
Offline

Joined: September 17th, 2005, 6:43 pm
Posts: 242
It has taken me about 2 days worth of coding, and re-coding, but I think I finally got it.
Code:
regread, current, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\TimeZoneInformation, standardname
RegRead, Difference, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\%current%, Display
stringmid, count1, difference, 5,3
Stringmid, count2, difference, 9,2
urldownloadtofile, http://132.163.4.101:14, time.txt
FileReadLine, time, time.txt, 2
StringSplit, time, time, %A_Space%
stringreplace, date, time2, -,,all
stringreplace, time, time3, :,,all
  if date is not number
   {
    msgbox There was a problem with the time synchronization`nPlease try again at a later time.
    exitapp
   }
  today = 20%date%%time%
  today += %count1%, hh
  today += %count2%, mm
  formattime, temp, %today%
  stringmid, year, today, 3,2
  stringmid, month, today, 5,2
  stringmid, day, today, 7,2
  stringmid, hour, today, 9,2
  stringmid, min, today, 11,2
  stringmid, sec, today, 13,2
FileAppend, date %day%-%month%-%year%`ntime %hour%:%min%:%sec%.00, %a_scriptdir%\temptime.bat ; Create the batch file that actually changes the time
loop, %USERPROFILE%\Local Settings\Temporary Internet Files\132.163*.*, 1, 1
{
 filedelete, %A_LoopFileFullPath% ; if you don't do this, it will keep the same time as you last ran the program.
}
filedelete, %a_scriptdir%\time.txt
runwait, %a_scriptdir%\temptime.bat,, hide ;run it :)
FileDelete, %a_scriptdir%\temptime.bat ; start with a fresh file

Let me know if there is something that I could do better, easier, or whatever.

Side note:
this does not work with Jerusalem, or kuala, lumpur singapore. I will update that after I get a nap :)


Last edited by maestrith on January 20th, 2006, 8:57 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 20th, 2006, 9:11 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
Ok, you asked for it.

here are my comments:
a) The loop at the beginning should be more specificly name the files that get deleted, so that only the correct once get removed. 132*.* is a little bit too general.

b) I would place this line
Code:
filedelete, %a_scriptdir%\time.txt
right after the time when the file isn't needed any more. So that no junk is left on the disc. I know that it is easier for debuging to delete it at the next run to have it this way.

c) The lines
Code:
StringMid, variant, difference, 5, 6
stringleft, count1, variant, 3
Stringright, count2, variant, 2
Could be replaced with just two StringMid.

d) The code will onyl continue after URLDownlaodToFile, when URLDownlaodToFile is done downlaoded. So these lines
Code:
urldownloadtofile, http://132.163.4.101:14, time.txt
read:
FileReadLine, time, time.txt, 2
if time =
 {
  goto read ; loop until the file downloads
 }
do not work. 1) the loop will only be executed after the file is doenloaded. 2) if the file couldn't be downloaded it will contain some other text then the desired one. Thus you have to check for other things to make sure you got the correct file. E.g. FileSize, the file content or the length of the file content

e) If the download fails, the code should give feedback to user and exit.

f) I believe that you do not need to create a batch file to run "date". I guess you could use the run command directly in the script to execute that comand.

Happy scripting.

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Thanks for the input!!!
PostPosted: January 20th, 2006, 8:39 pm 
Offline

Joined: September 17th, 2005, 6:43 pm
Posts: 242
The things we tend to overlook when in the middle of writing a script :) after I make the adjustments to the script I will have it delete the temp file right away. Now that I think about it, some sort of varification is needed for the download of the file...maybe a restart of the script or something might be a good alternative. I will do my best to fix it so that it is a bit more user friendly. The original intent for the script is for a "lockdown" code that I am writing for my kids computers to make sure that after boot, the time is right so that the triggers for "bedtime" and what not are accurate. As far as the temp file, the actual name of it is something like 132.163.4.[1] or something, similar, and it's not something that I could figure out how to phrayse it to delete it...I changed it to 132.163*.*, that should narrow it down a bit.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2006, 3:50 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
In case it's useful, you can also change the system date and time via DllCall as shown in the examples at the bottom of the DllCall page.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: DllCall
PostPosted: January 21st, 2006, 10:15 am 
Offline

Joined: September 17th, 2005, 6:43 pm
Posts: 242
I have read over the dllcall page, and I have a quick question in regard to the time setting application of it. Is the DLL available in windows, or is it something that I would have to write myself to interface with the windows clock. Thanks in advance.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 21st, 2006, 1:53 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
SetSystemTime() should be available in all versions of Windows.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 13th, 2006, 10:00 pm 
Offline

Joined: February 9th, 2006, 6:17 pm
Posts: 11
Thanks for the script! Very, very useful!!

Although that time zone registry read didn't work for me.

I am having Hungarian Windows, and it is the translated name of the timezone stored in SYSTEM\CurrentControlSet\Control\TimeZoneInformation\standardname entry. ("Közép-európai téli idő")
Meanwhile the subkeys of SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones are identified by their English names. ("Central European Standard Time") :)

Fortunately, its "Std" string stores the Hungarian name, so a loop can help to find the appropriate subkey:
Code:
Loop, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones, 2
{
  RegRead, lStd, HKEY_LOCAL_MACHINE, %A_LoopRegSubKey%\%A_LoopRegName%, Std
  if lStd = %current%
    RegRead, Difference, HKEY_LOCAL_MACHINE, %A_LoopRegSubKey%\%A_LoopRegName%, Display
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2006, 1:02 pm 
@maestrith
Good script!
I want change the time for my zone (-2h)
I tray to change the numbers of count1, difference, x,x
but no result :oops:
Code:
stringmid, count1, difference, 5,3
Stringmid, count2, difference, 9,2

How to proced???
Thank you in advance!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 14th, 2006, 2:21 pm 
Offline

Joined: February 9th, 2006, 6:17 pm
Posts: 11
gguueesstt wrote:
I want change the time for my zone (-2h)
I tray to change the numbers of count1, difference, x,x
but no result :oops:


No, that is a string related command, not a subtract operator. It tries to cut out a part of a string. For example cut the "-10" from the string "(GMT-10:00) Hawaii".

I guess you are facing the same problem as I. The problem can come from the registry, where your computer may store the informations of time zones in a different way than maestrith's comp does.

Why don't you to try my code in my last (and the very first here as well:) ) post.

So instead of
Code:
RegRead, Difference, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\%current%, Display


use this one:

Code:
Loop, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones, 2
{
  RegRead, lStd, HKEY_LOCAL_MACHINE, %A_LoopRegSubKey%\%A_LoopRegName%, Std
  if lStd = %current%
    RegRead, Difference, HKEY_LOCAL_MACHINE, %A_LoopRegSubKey%\%A_LoopRegName%, Display
}


I hope it will help


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2006, 3:19 am 
Thank you, Humigeri, I try but make the same result;
now I think is better copy in the temptime.bat date (must be ordered 14 02 2006) and time (eg 13:08:44 (-2)) but I am stuck....

my time.txt:
Code:
53780 06-02-14 13:08:44 00 0 0 206.7 UTC(NIST) *


Code:
urldownloadtofile, http://132.163.4.101:14, time.txt
FileDelete, %a_scriptdir%\temptime.bat

FileReadLine, time, time.txt, 2
StringSplit, time, time, %A_Space%
;MsgBox, %time%.
StringSplit, word_array, time, %A_Space%,
;MsgBox, %word_array3%.
MsgBox, %word_array2%.

?????? How to....???
Somebody can help me please?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2006, 10:36 am 
Offline

Joined: February 9th, 2006, 6:17 pm
Posts: 11
Well, gguueessttt, I think I don't understand your problem exactly.

You succeed to change your system time, but it gains 2 hours, or you cannot change the time at all?

What did you changed compared to meastrith's script?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2006, 2:29 pm 
Hi, Humigeri.
I'm apologize for my poor explication and English.

Whit your modify script the result is: (the same
13:24

time.txt
53781 06-02-15 13:24:33 00 0 0 832.7 UTC(NIST) *

I need 11:24

Thank you!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2006, 6:10 pm 
Offline

Joined: February 9th, 2006, 6:17 pm
Posts: 11
Well, if nothing can help, you should replace
Code:
today += %count1%, hh

with
Code:
today += -2, hh


I guess, your time zone doesn't change so frequently, so i think it's nothing wrong with this bit of hardcoding.

Anyway, I would be interested in what is your registry value of "HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\TimeZoneInformation, standardname", and what kind of subkeys are defined under "HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones". Those values must cause your problem, definitely.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 15th, 2006, 8:34 pm 
Hi Humigeri,
Now run fine, thank you very much!

My registry value of "HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Control\TimeZoneInformation, standardname",
is "Hora oficial do Brasil", but I'm interested at -2

Thank you again.
Tchau!


Report this post
Top
  
Reply with quote  
 Post subject: Error msg.
PostPosted: April 8th, 2008, 9:24 pm 
Offline

Joined: October 18th, 2007, 7:08 pm
Posts: 32
Im not sure what's wrong, my level of scripting is pretty rudimentary, im sure it's something easy.

The url http://132.163.4.101:14 seems to work fine, but no txt file is created.

"Error at line 19.

Line Text: if date is no number
Error: This line does not contain a recognized action

The program will exit."


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bowen666 and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group