Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Set Your Computer Clock Via Internet [optimised by Laszlo]


  • Please log in to reply
52 replies to this topic
SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
* Atomic Time Synchronisation *

The optimised version by Laszlo (for Windows 98 & Windows 2000 ) * Code Updated : 30-Nov-2006 *

UrlDownLoadToFile [color=blue]http://132.163.4.101:14[/color], %A_ScriptDir%\$.time 
If (ErrorLevel) { 
   MsgBox Time Server is not available 
   ExitApp 
} 
FileReadLine x, %A_ScriptDir%\$.time, 2 

VarSetCapacity(T,16,0) 
DllCall("RtlFillMemory", UInt,&T,   UInt,1, UChar, 20 SubStr(x,7,2)) 
DllCall("RtlFillMemory", UInt,&T+1, UInt,1, UChar,(20 SubStr(x,7,2))>>8) 
DllCall("RtlFillMemory", UInt,&T+2, UInt,1, UChar,SubStr(x,10,2)) 
DllCall("RtlFillMemory", UInt,&T+6, UInt,1, UChar,SubStr(x,13,2)) 
DllCall("RtlFillMemory", UInt,&T+8, UInt,1, UChar,SubStr(x,16,2)) 
DllCall("RtlFillMemory", UInt,&T+10,UInt,1, UChar,SubStr(x,19,2)) 
DllCall("RtlFillMemory", UInt,&T+12,UInt,1, UChar,SubStr(x,22,2)) 

DllCall("SetSystemTime", Str,T) 
PostMessage 0x1E,,,,ahk_class Shell_TrayWnd 
Return

Note: SubStr() requires AHK v1.0.46+. See the original post for an older version of the above script

** Time Servers **

[*:5trqv93t] http://132.163.4.101:13
[*:5trqv93t] http://132.163.4.101:14
[*:5trqv93t] http://132.163.4.102:13
[*:5trqv93t] http://132.163.4.102:14
[*:5trqv93t] http://132.163.4.103:13
[*:5trqv93t] http://132.163.4.103:14

[*:5trqv93t] http://207.126.98.204:14

[*:5trqv93t] http://131.107.1.10:13
[*:5trqv93t] http://129.6.15.28:13
[*:5trqv93t] http://129.6.15.29:13
[*:5trqv93t] http://128.138.140.44:13
[*:5trqv93t] http://192.43.244.18:13
[*:5trqv93t] http://69.25.96.13:13
[*:5trqv93t] http://216.200.93.8:13
[*:5trqv93t] http://208.184.49.9:13
[*:5trqv93t] http://207.200.81.113:13
[*:5trqv93t] http://64.236.96.53:13
[*:5trqv93t] http://68.216.79.113:13
The following is for WIN XP

;The Automatically synchronize checkbox should be checked in the Control Panel / Date and Time / Internet Time window
Run RunDll32.exe shell32.dll`,Control_RunDLL timedate.cpl 
WinWaitActive Date and Time Properties ahk_class #32770 
Send ^{TAB 2}!u{Enter}

Edit: 18-Feb-2006 : To preserve the continuity of this topic, my original code is provided as a Text File

Regards, :) [/list]
kWo4Lk1.png

polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
Nice script, but there is one thing:
CreateIni:
FileAppend,[TIME_SYNC]`n,%IniFile%
FileAppend,OnceIn(Days)=0`n,%IniFile%
FileAppend,URL=http://132.163.4.101:14/`n`n,%IniFile%
FileAppend,[DATA]`n,%IniFile%
FileAppend,Index(DL)=0`n,%IniFile%
FileAppend,LastRUN(UTC)=`n,%IniFile%
FileAppend,RFC867=`n,%IniFile%
Return
Shouldn't you be using IniWrite for this? Here's an improved version:
CreateIni:
IniWrite, 0, %IniFile%, TIME_SYNC, OnceIn(Days)
IniWrite, http://132.163.4.101:14/, %IniFile%, TIME_SYNC, URL
IniWrite, 0, %IniFile%, DATA, Index(DL)
IniWrite, , %IniFile%, DATA, LastRUN(UTC)
IniWrite, , %IniFile%, DATA, RFC867
Return

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear Titan, thanks :)

but there is one thing:Shouldn't you be using IniWrite for this?


Please refer to my post Blank Line in INI file? (IniWrite), where

I observed that WIN 98 & WIN XP handles ".INI" files differently

When a new Section is being added to .INI files :-
WIN 98 removes all empty lines at the end of the file, adds a linefeed and then adds the new section
whereas
WIN XP adds the new section immediately after the last line.

I tested this by inserting 10 blank lines in a .INI file and then INIWRITEd a new section. WIN 98 removes all the empty lines, whereas WIN XP writes next to the last line (retaining 10 empty lines in between)


I use WIN98 SE, so the empty line between the Sections is default, but not so in WIN XP. I plan to extend this (TimeSync.ahk) script with a GUI & so I expect more sections will be added to INI and so I have chosen Fileappend over IniWrite.
FileAppend,[TIME_SYNC]`n,%IniFile%
FileAppend,OnceIn(Days)=0`n,%IniFile%
FileAppend,URL=http://132.163.4.101:14/`n`n,%IniFile%
FileAppend,[DATA]`n,%IniFile%
FileAppend,Index(DL)=0`n,%IniFile%
FileAppend,LastRUN(UTC)=`n,%IniFile%
FileAppend,RFC867=`n,%IniFile%
Regards :)
kWo4Lk1.png

humigeri
  • Members
  • 11 posts
  • Last active: Apr 07 2006 08:07 AM
  • Joined: 09 Feb 2006
Correct me if i am mistaken: this script does the same as meastrith's, except for the use of "SetSystemTime" and ini file.

And I can't see either how time zone adjustments will be applied.

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear humigeri,

Correct me if i am mistaken: this script does the same as meastrith's, except for the use of "SetSystemTime" and ini file.


Yes! I was inspired by maestrith, and have given due credit to him & his post (see the last lines of my code)

And I can't see either how time zone adjustments will be applied.

AFAIK:
[*:2tx07vov]The System's Internal Time is maintained as UT-C
[*:2tx07vov]System Clock time includes the bias (difference between Time Zones) to System's Internal TimeSince I am Updating the System`s Internal Time (and NOT System Clock), I pass the UTC time as a parameter to SetSystemTime(). Windows OS adds the TimeZone difference (bias as in Registry) and updates the System Clock.

You may change your clock time (by an hour) and run my code. It should set the exact time according to the Timezone settings in your registry.

Regards :)
kWo4Lk1.png

humigeri
  • Members
  • 11 posts
  • Last active: Apr 07 2006 08:07 AM
  • Joined: 09 Feb 2006

Yes! I was inspired by maestrith, and have given due credit to him & his post (see the last lines of my code)


ok, i had seen those lines, just wanted to be sure, the script works the way i think, or there are any other benefits compared to that one.

[*]The System's Internal Time is maintained as UT-C
[*]System Clock time includes the bias (difference between Time Zones) to System's Internal Time


Ok, I see. Didn't realize, that DllCall("SetSystemTime") expects a UTC time.

Thanks for the answer!

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Dear humigeri,

ok, i had seen those lines, just wanted to be sure, the script works the way i think, or there are any other benefits compared to that one.


The main benefit is that I use WIN 98 SE and my script will (hopefully!) run in all Windows version > 95.
What I have really borrowed from maestrith's script is the URL of NIST, before which I was not aware of
NIST using ASCII. Chris' post on that topic [ about SetSystemTime() ] gave me the light to write this script.
The other benefit is that my script does not refer the Windows Registry.

Anyways!

For people who would like to tweak the Time Zone Settings, but uncomfortable with Windows REGEDIT
may use the Time Zone Editor 22.72kb bundled with Windows 98 as Resource Kit.

WIN 98`s Time Zone Editor as seen in WIN XP (Tze_SnapShot.gif 14kb, Res: 492x297)
Posted Image

Regards :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This script is faster and easier to activate than right-clicking on the tray clock, select Adjust Date/Time, click on the Internet Time tab and on the Update Now button (which results in the same time update in Windows XP). I simplified it a little: there is no need for the ini file, except to keep track of the number of calls, so a different fake parameter could be attached to the url, to enforce a new download (instead of using a cached file).

If we don't delete the last downloaded file, we can use its content as the fake parameter. Since the true time is increasing, we can be sure that no conflicting page exists in cache.
FileReadLine x, $$.time, 2
UrlDownLoadToFile http://132.163.4.101:14/?x=%x%, $$.time
If (ErrorLevel) {
   MsgBox Time Server is not available
   ExitApp
}
FileReadLine x, $$.time, 2

VarSetCapacity(T,16,0)
DllCall("RtlFillMemory", UInt, &T,   UInt,1, UChar, 20 StringMid(x,7,2))
DllCall("RtlFillMemory", UInt, &T+1, UInt,1, UChar,(20 StringMid(x,7,2))>>8)
DllCall("RtlFillMemory", UInt, &T+2, UInt,1, UChar,StringMid(x,10,2))
DllCall("RtlFillMemory", UInt, &T+6, UInt,1, UChar,StringMid(x,13,2))
DllCall("RtlFillMemory", UInt, &T+8, UInt,1, UChar,StringMid(x,16,2))
DllCall("RtlFillMemory", UInt, &T+10,UInt,1, UChar,StringMid(x,19,2))
DllCall("RtlFillMemory", UInt, &T+12,UInt,1, UChar,StringMid(x,22,2))

DllCall("SetSystemTime", str,T)
PostMessage 0x1E,,,,ahk_class Shell_TrayWnd
Return

StringMid(String,Start,Len) {
   StringMid S, String, Start, Len
   Return S
}

With AHK version 1.0.46.00+ it can be simplified: there is no need for the fake parameter to force download and there is a new SubStr() built in function.
UrlDownLoadToFile http://132.163.4.101:14, %A_ScriptDir%\$.time
If (ErrorLevel) {
   MsgBox Time Server is not available
   ExitApp
}
FileReadLine x, %A_ScriptDir%\$.time, 2

VarSetCapacity(T,16,0)
DllCall("RtlFillMemory", UInt,&T,   UInt,1, UChar, 20 SubStr(x,7,2))
DllCall("RtlFillMemory", UInt,&T+1, UInt,1, UChar,(20 SubStr(x,7,2))>>8)
DllCall("RtlFillMemory", UInt,&T+2, UInt,1, UChar,SubStr(x,10,2))
DllCall("RtlFillMemory", UInt,&T+6, UInt,1, UChar,SubStr(x,13,2))
DllCall("RtlFillMemory", UInt,&T+8, UInt,1, UChar,SubStr(x,16,2))
DllCall("RtlFillMemory", UInt,&T+10,UInt,1, UChar,SubStr(x,19,2))
DllCall("RtlFillMemory", UInt,&T+12,UInt,1, UChar,SubStr(x,22,2))

DllCall("SetSystemTime", Str,T)
PostMessage 0x1E,,,,ahk_class Shell_TrayWnd
Return


SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
clapping.gif
Posted Image

Thank you Laszlo ..
Optimum coding :)

Regards, :)
kWo4Lk1.png

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
Thanks! Nice GIF!

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
If the Automatically synchronize... checkbox is checked in the Control Panel / Date and Time / Internet Time window, the following three line script should do the work the Windows XP way.
Run Control.exe TIMEDATE.CPL

WinWaitActive Date and Time Properties ahk_class #32770

Send ^{TAB 2}!u{Enter}
Windows 98 users should stick to the AHK solution above, which also seems to be much faster on XP.

maestrith
  • Members
  • 786 posts
  • Last active: Apr 10 2019 01:28 PM
  • Joined: 17 Sep 2005
thanks for the shout out :) glad to see my script inspired some thought :):)

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005

Windows 98 users should stick to the AHK solution above, which also seems to be much faster on XP.


Your optimised code works fine with Windows 2000

Regards, :)
kWo4Lk1.png

Loriss
  • Members
  • 62 posts
  • Last active: Oct 09 2008 05:23 PM
  • Joined: 26 Jul 2004
This Url : http://132.163.4.101:14
is fequent down.
Is There any other Url to get the time.txt ?
Loriss

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
There is a list in Windows XP, Date and Time Properties / Internet Time tab.