Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 06, 2016, 02:22:56 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Idea : One Shot System Time Sync  (Read 1927 times)

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Idea : One Shot System Time Sync
« on: May 24, 2016, 04:20:45 PM »
I find when I WiFi that the WiFi routers block the Windows Time Service.  I thought it may be a nice idea for a small utility that does a one shot time sync when a button is clicked.  It could sit in the tray.  Perhaps with a command line switch so that it syncs the time and exits without showing a Tray Icon.

Right now what I am doing is getting the exact time off the web, then using the time command on the command line.  It would be nicer just to hit a button and have it compensate for AM/PM etc..

This is mainly aimed at my Laptop so I am looking more for a manual trigger than recurrent as I may not be connected to the net when the interval expires.

I found a few ahk scripts on the forum that use the IE activex control to get the time, but they don't quite do the whole job.  Sort of fragments from back around 2006.

The simpler the better.  :)

Edit:  this thread shows how to get the tine using the ie object avoiding the router block.


« Last Edit: May 24, 2016, 04:26:21 PM by MilesAhead »

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 2,925
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #1 on: May 24, 2016, 04:36:22 PM »
I'm not sure if it's exactly what you want, but you might try TimeSync, freeware by Horst Schaeffer:

Quote
TimeSync gets the current time from a NIST server, and adjusts the PC clock if necessary. Although the exact time is also supplied by Windows or (probably) by your router, you may want to have an extra tool that checks the time at your will.

Time and date are displayed according to the user's regional settings. Accuracy is usually within a second. TimeSync will try alternative servers, in case the time cannot be obtained from the preferred server.

TimeSync Option /auto is provided to run TimeSync from the the Windows task scheduler. In this mode the TimeSync window will not show if the clock offset is under a given minimum.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #2 on: May 24, 2016, 05:57:42 PM »
I believe I already tried TimeSync and several others similar.  It seems that anything that goes to any of the atomic clocks is blocked by the WiFi routers here at the college.  Even Windows own time service generates an error no matter which time server I select.

I did try a snippet from one of the IE object scripts in AHK.  It did return the time as a string.. but in 12 hour format with no GUI.  It was just there to service some other program by periodically fetching the exact time.  I think the reason it was not blocked was that it just made a call to www.timeanddate.com rather than one of the atomic time serers.

I know I could wrestle with it and come up with something.  But especially in AHK my Guis are  lacking in spiff factor.  :)

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #3 on: May 24, 2016, 06:59:09 PM »
Just to be sure, did you try Cmdtime from here?:  http://www.softshape...download/cmdtime.zip

I've used it for years but, as you said, it might be blocked.  If that doesn't work, I'll see what I can put together.

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #4 on: May 25, 2016, 05:42:40 AM »
Code: Text [Select]
  1. net time \\computername /set

For computername you can try a server on the local network and hopefully get one that hasn't got an exceptionally paranoid firewall.

eg.
Code: Text [Select]
  1. C:\>net time \\192.168.0.208 /set
  2. Current time at \\192.168.0.208 is 25/05/2016 20:42:10
  3.  
  4. The current local clock is 25/05/2016 20:41:58
  5. Do you want to set the local computer's time to match the
  6. time at \\192.168.0.208? (Y/N) [Y]:

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #5 on: May 25, 2016, 07:15:17 AM »
Just to be sure, did you try Cmdtime from here?:  http://www.softshape...download/cmdtime.zip

I've used it for years but, as you said, it might be blocked.  If that doesn't work, I'll see what I can put together.

I don't think I can get there from here.  All servers I try return either "cannot reach the time server" or "permission denied."

It is not the end of the world if I have to type the time command into a command prompt.  But if you made something that looked good that would be preferable.   :Thmbsup:


MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #6 on: May 25, 2016, 07:23:13 AM »
For computername you can try a server on the local network and hopefully get one that hasn't got an exceptionally paranoid firewall.


Something must have happened when they installed new equipment or something.  Logging into my web site control panel used to work fine over the WiFi.  Now I have to get on one of the wired machines to log in.  Fortunately my site is pretty stable now.  I do not have to update it often.

Edit: apparently there is a Linux utility called htpdate that gets the time from the headers of web pages specifically for use when ntp port 123 is blocked.  I looked around but could not find any Windows port of it less than 10 years old.

« Last Edit: May 25, 2016, 07:49:50 AM by MilesAhead »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #7 on: May 25, 2016, 12:04:45 PM »
Edit: apparently there is a Linux utility called htpdate that gets the time from the headers of web pages specifically for use when ntp port 123 is blocked.  I looked around but could not find any Windows port of it less than 10 years old.

Ten years old is fine if they still work, eh?  Did you try any of them?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #8 on: May 25, 2016, 12:30:06 PM »
Edit: apparently there is a Linux utility called htpdate that gets the time from the headers of web pages specifically for use when ntp port 123 is blocked.  I looked around but could not find any Windows port of it less than 10 years old.

Ten years old is fine if they still work, eh?  Did you try any of them?

I found a recend win32 version here:
http://www.rkeene.or...el/htp/win32/stable/

It seems to work ok from and admin command prompt.  I downloaded the exe with the highest version number, and scanned it with VirusTotal.  Then I renamed it to simply htpdate.

For those interested this command line worked for me:
htpdate www.timeanddate.com  set

Then I go on the wb to
Time.is
and it tells me how close my clock is to the time server.

I guess I can do an ahk to run it without showing the command prompt.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #9 on: May 25, 2016, 02:58:35 PM »
Just for grins, here's an AHK solution that uses http://www.timeapi.org but doesn't use any third-party executables.

Code: Autohotkey [Select]
  1. ; Set timezone value to your timezone.
  2. myTimeZone := "CDT"
  3.  
  4. myTempFile := A_ScriptDir . "\~" . A_Now . ".txt"
  5. URLDownloadToFile, http://www.timeapi.org/%myTimeZone%/, % myTempFile
  6. FileRead, myTime, % myTempFile
  7. FileDelete, % myTempFile
  8.  
  9. ; Sample output: 2016-05-25T13:24:22-06:00
  10. RegExMatch( myTime, "^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d:\d\d:\d\d)", myMatch )
  11.  
  12. ; Sample matches:
  13. ; myMatch1 = 2016
  14. ; myMatch2 = 05
  15. ; myMatch3 = 25
  16. ; myMatch4 = 13:24:22
  17.  
  18. ; Set the date.
  19. Run, %COMSPEC% /C date %myMatch2%-%myMatch3%-%myMatch1%, , Hide
  20.  
  21. ; Set the time.
  22. Run, %COMSPEC% /C time %myMatch4%                      , , Hide

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #10 on: May 25, 2016, 03:55:20 PM »
Thanks skwire.  :)

I got bogged down trying to run the htpdate command as administrator to avoid typing the stuff in.  Then I did a .cmd file for the same reason.  I finally remembered I could simply go into the compatibility tab for the compiled program and set it to run as admin.. :-[

At least now I can click an icon in the taskbar.  It sounds a chime as clue something is happening.  By the time the icon departs the system tray the time display should change.

Code: Autohotkey [Select]
  1. RunWait,htpdate www.timeanddate.com set,,Hide

For grins after running it I use the Time.is website to get a read sync and tell me how close my clock is to standard.  All the variances have been within a second so far.  Better than typing in the time in a prompt adding on a few seconds.  :)


Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,294
    • View Profile
    • www.StoicJoker.com
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #11 on: May 26, 2016, 06:52:21 AM »
For grins after running it I use the Time.is website to get a read sync and tell me how close my clock is to standard.

Damn that is a handy site, never heard of it before. I just tried it cold on our system here and got:
Quote
The difference from Time.is was +0.023 seconds (±0.021 seconds).

I gotta go back and figure out what I did to the time service on our (VM) host machines...it's apparently working.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #12 on: May 26, 2016, 07:09:34 AM »
Damn that is a handy site, never heard of it before.

Me either.  I googled "exact time" and it came up high in the results.  I still can't believe that for a long while I fooled around with that stupid Gui Windows time set thing on the clock.  Man is that an annoying way to try to set the time!  By the time you mess around with the little up arrows the time has gone by.  Much easier to use "time" on the command line.  :)

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,474
    • View Profile
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #13 on: May 28, 2016, 08:50:39 PM »
The Powershell version:

Code: PowerShell [Select]
  1. # https://social.technet.microsoft.com/Forums/windowsserver/en-US/1a4467e5-9b9e-4ef1-9b22-4af3a1a77362/setting-system-time-with-powershell?forum=winserverpowershell
  2. function Set-Time ([string]$dateTime) {
  3.   Set-Date (Get-Date $dateTime)
  4. }
  5. Set-Time (Invoke-WebRequest -Uri "http://www.google.com").Headers.Date | Out-Null

Needs a admin privileged console due to the Set-Date cmdlet.

Or create a shortcut with the following as the Target:
Code: Text [Select]
  1. %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -sta -noprofile -executionpolicy bypass -Window Hidden -Command "& Set-Date(Get-Date([string](iwr 'http://www.google.com').Headers.Date)) | Out-Null"

And set Run as administrator under Properties->Shortcut->Advanced.
« Last Edit: May 29, 2016, 05:02:54 AM by 4wd »

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,283
    • View Profile
    • Miles Ahead Software
    • Donate to Member
Re: Idea : One Shot System Time Sync
« Reply #14 on: May 29, 2016, 01:02:00 PM »
The Powershell version:

Thanks for the contribution.