Get Internet Date/Time

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rdemyan via AccessMonster.com

    #1

    Get Internet Date/Time

    Is there a way to get the internet date/time. I saw an article that uses
    WinSock, but WinSock doesn't seem to be available in Access.

    I want to verify that the date/time on the local PC running my application is
    correct, so I was hoping I could get the Internet date/time. I understand
    that there is a NTP protocol to do this.

    Thanks.

    --
    Message posted via http://www.accessmonster.com
  • Tom van Stiphout

    #2
    Re: Get Internet Date/Time

    On Thu, 16 Mar 2006 03:47:09 GMT, "rdemyan via AccessMonster.c om"
    <u6836@uwe> wrote:

    Check with the MSFT knowledge base:


    -Tom.

    [color=blue]
    >Is there a way to get the internet date/time. I saw an article that uses
    >WinSock, but WinSock doesn't seem to be available in Access.
    >
    >I want to verify that the date/time on the local PC running my application is
    >correct, so I was hoping I could get the Internet date/time. I understand
    >that there is a NTP protocol to do this.
    >
    >Thanks.[/color]

    Comment

    • rdemyan via AccessMonster.com

      #3
      Re: Get Internet Date/Time

      Thanks for the link, but I don't understand how I can incorporate this into
      my Access application.

      Tom van Stiphout wrote:[color=blue]
      >Check with the MSFT knowledge base:
      >http://support.microsoft.com/default...b;en-us;172831
      >
      >-Tom.
      >[color=green]
      >>Is there a way to get the internet date/time. I saw an article that uses
      >>WinSock, but WinSock doesn't seem to be available in Access.[/color]
      >[quoted text clipped - 4 lines][color=green]
      >>
      >>Thanks.[/color][/color]

      --
      Message posted via AccessMonster.c om

      Comment

      • John Mishefske

        #4
        Re: Get Internet Date/Time

        rdemyan via AccessMonster.c om wrote:[color=blue]
        > Thanks for the link, but I don't understand how I can incorporate this into
        > my Access application.[/color]

        Generally you don't; its implemented at the operating system level. Check out
        the W32Time service. The Microsoft KnowledgeBase surely has some docs on this.

        --
        '---------------
        'John Mishefske
        '---------------

        Comment

        • rdemyan via AccessMonster.com

          #5
          Re: Get Internet Date/Time

          I tried to find the W32Time.exe on my computer (running Windows XP home
          edition) and couldn't. Since I want to use the "Internet Time" for
          verification purposes for my trial versions, I can't count on prospective
          users installing W32Time.exe if they don't have it. Further, some of my
          potential clients work for companies that have "locked down" PCs (no
          executables, no zip file attachments to e-mails,etc.).

          John Mishefske wrote:[color=blue][color=green]
          >> Thanks for the link, but I don't understand how I can incorporate this into
          >> my Access application.[/color]
          >
          >Generally you don't; its implemented at the operating system level. Check out
          >the W32Time service. The Microsoft KnowledgeBase surely has some docs on this.
          >[/color]

          --
          Message posted via AccessMonster.c om

          Comment

          • Anthony England

            #6
            Re: Get Internet Date/Time


            "rdemyan via AccessMonster.c om" <u6836@uwe> wrote in message
            news:5d5836e81b d67@uwe...[color=blue]
            >I tried to find the W32Time.exe on my computer (running Windows XP home
            > edition) and couldn't. Since I want to use the "Internet Time" for
            > verification purposes for my trial versions, I can't count on prospective
            > users installing W32Time.exe if they don't have it. Further, some of my
            > potential clients work for companies that have "locked down" PCs (no
            > executables, no zip file attachments to e-mails,etc.).[/color]


            But they will let the users install your program which will automatically
            try to connect across the internet to carry out a task which is actually for
            your benefit? Could they even tell what it was doing - to back up your
            claim that it was only checking the time?
            I would go another route to securing you trial version - like putting a
            maximum limit on the number of times the database gets opened.


            Comment

            • rdemyan via AccessMonster.com

              #7
              Re: Get Internet Date/Time

              Yes, I've considered this. But all you have to do is reinstall the trial
              version to get around it. There's other tricks like creating a text file the
              first time the app starts up which prevents subsequent reinstallation and so
              on.

              Still, I'm really surprised that this is so difficult. My planned approach
              is to hardcode a start date in my app and then provide around 30 days or so
              of use. The number of prospective trial users is relatively small, so this
              is not a burden. By checking the "Internet time" that would prevent users
              from setting the clock back. I think this could work quite well, but
              without a means of getting the internet time, it becomes difficult.

              Anthony England wrote:[color=blue][color=green]
              >>I tried to find the W32Time.exe on my computer (running Windows XP home
              >> edition) and couldn't. Since I want to use the "Internet Time" for
              >> verification purposes for my trial versions, I can't count on prospective
              >> users installing W32Time.exe if they don't have it. Further, some of my
              >> potential clients work for companies that have "locked down" PCs (no
              >> executables, no zip file attachments to e-mails,etc.).[/color]
              >
              >But they will let the users install your program which will automatically
              >try to connect across the internet to carry out a task which is actually for
              >your benefit? Could they even tell what it was doing - to back up your
              >claim that it was only checking the time?
              >I would go another route to securing you trial version - like putting a
              >maximum limit on the number of times the database gets opened.[/color]

              --
              Message posted via AccessMonster.c om

              Comment

              • Lyle Fairfield

                #8
                Re: Get Internet Date/Time

                Your application is so valuable that users will reset their system time
                to be able to use it. Woohoo!

                You might be able to thwart these evil-doers on modern machines with

                Private Declare Function IsUserAnAdmin Lib "shell32" () As Long

                Public Sub SyncTime()
                If IsUserAnAdmin Then
                Shell "w32tm /config /syncfromflags:m anual
                /manualpeerlist: time.nist.gov"
                Shell "w32tm /config /update"
                Else
                MsgBox "You do not have required rights.", vbExclamation,
                "Cannot Synchronise Time"
                End If
                End Sub

                which will un-reset their system time.

                Of course, it's unethical to mess with users' systems but it's just
                "bringing justice to them"!

                Uh huh!

                Comment

                • Rick Brandt

                  #9
                  Re: Get Internet Date/Time

                  rdemyan via AccessMonster.c om wrote:[color=blue]
                  > Yes, I've considered this. But all you have to do is reinstall the
                  > trial version to get around it. There's other tricks like creating a
                  > text file the first time the app starts up which prevents subsequent
                  > reinstallation and so on.
                  >
                  > Still, I'm really surprised that this is so difficult. My planned
                  > approach is to hardcode a start date in my app and then provide
                  > around 30 days or so of use. The number of prospective trial users
                  > is relatively small, so this is not a burden. By checking the
                  > "Internet time" that would prevent users from setting the clock back.
                  > I think this could work quite well, but without a means of getting
                  > the internet time, it becomes difficult.[/color]

                  Possible solution....

                  Record the System DateTime EVERY time the app starts and store in a table.
                  Use the first one to establish the beginning of the trial period and if you
                  ever see a System DateTime that is prior to one previously captured then you
                  know they've set their clock back and you can still disable the app. You'd
                  need to allow for reverting to standard time in the fall, but that would
                  simply be a matter of allowing changes of an hour or so, but nothing larger.

                  --
                  I don't check the Email account attached
                  to this message. Send instead to...
                  RBrandt at Hunter dot com



                  Comment

                  • rdemyan via AccessMonster.com

                    #10
                    Re: Get Internet Date/Time

                    Thanks, Rick.

                    Yes, this is my backup plan. However, if someone reinstalls the trial on a
                    PC where the date has been set back, then I think this technique won't stop
                    that. Getting the internet time would.

                    Again, I'm just surprised at how difficult it is to get the Internet time. I
                    might monkey around with Lyle's suggestion, but I don't want to reset the
                    clock, I just want to get the Internet time and compare it to the PC clock so
                    I can abort opening the app if needed.


                    Rick Brandt wrote:[color=blue][color=green]
                    >> Yes, I've considered this. But all you have to do is reinstall the
                    >> trial version to get around it. There's other tricks like creating a[/color]
                    >[quoted text clipped - 8 lines][color=green]
                    >> I think this could work quite well, but without a means of getting
                    >> the internet time, it becomes difficult.[/color]
                    >
                    >Possible solution....
                    >
                    >Record the System DateTime EVERY time the app starts and store in a table.
                    >Use the first one to establish the beginning of the trial period and if you
                    >ever see a System DateTime that is prior to one previously captured then you
                    >know they've set their clock back and you can still disable the app. You'd
                    >need to allow for reverting to standard time in the fall, but that would
                    >simply be a matter of allowing changes of an hour or so, but nothing larger.
                    >[/color]

                    --
                    Message posted via AccessMonster.c om

                    Comment

                    • Rick Brandt

                      #11
                      Re: Get Internet Date/Time

                      rdemyan via AccessMonster.c om wrote:[color=blue]
                      > Thanks, Rick.
                      >
                      > Yes, this is my backup plan. However, if someone reinstalls the
                      > trial on a PC where the date has been set back, then I think this
                      > technique won't stop that. Getting the internet time would.
                      >
                      > Again, I'm just surprised at how difficult it is to get the Internet
                      > time. I might monkey around with Lyle's suggestion, but I don't want
                      > to reset the clock, I just want to get the Internet time and compare
                      > it to the PC clock so I can abort opening the app if needed.[/color]

                      Do you have access to a web server? A few of my apps have a security
                      feature in that before they can be used you have to run a "Security Wizard".
                      This sends an HTTP request to a java servlet I run on our web server and
                      sends to it an account number which is then authenticated on the server and
                      then a "SUCCESS" message is returned. The users must do this every time
                      they install on a new PC. In your case the web app could just return the
                      DateTime on the web server.

                      --
                      I don't check the Email account attached
                      to this message. Send instead to...
                      RBrandt at Hunter dot com


                      Comment

                      • rdemyan via AccessMonster.com

                        #12
                        Re: Get Internet Date/Time

                        Yeah, I've been wondering about this. Unfortunately, I am not very
                        knowledgable about the web.

                        My small company does have our website hosted by a webhosting company. I was
                        wondering if I couldn't somehow use their webserver (although it is a shared
                        webserver and not dedicated for us) to provide the date/time.

                        Any thoughts on that or suggestions?

                        Rick Brandt wrote:[color=blue][color=green]
                        >> Thanks, Rick.
                        >>[/color]
                        >[quoted text clipped - 6 lines][color=green]
                        >> to reset the clock, I just want to get the Internet time and compare
                        >> it to the PC clock so I can abort opening the app if needed.[/color]
                        >
                        >Do you have access to a web server? A few of my apps have a security
                        >feature in that before they can be used you have to run a "Security Wizard".
                        >This sends an HTTP request to a java servlet I run on our web server and
                        >sends to it an account number which is then authenticated on the server and
                        >then a "SUCCESS" message is returned. The users must do this every time
                        >they install on a new PC. In your case the web app could just return the
                        >DateTime on the web server.
                        >[/color]

                        --
                        Message posted via http://www.accessmonster.com

                        Comment

                        • Rick Brandt

                          #13
                          Re: Get Internet Date/Time

                          rdemyan via AccessMonster.c om wrote:[color=blue]
                          > Yeah, I've been wondering about this. Unfortunately, I am not very
                          > knowledgable about the web.
                          >
                          > My small company does have our website hosted by a webhosting
                          > company. I was wondering if I couldn't somehow use their webserver
                          > (although it is a shared webserver and not dedicated for us) to
                          > provide the date/time.
                          >
                          > Any thoughts on that or suggestions?[/color]

                          Well basically if you can find any publicly available web service that
                          serves the current time then you could make an HTTP request to that service.
                          All that would be left would be to figure out how to parse the response.

                          This example retrieves the date and (central) time from www.time.gov. At
                          least it does for me. I make no guarantees whether it will work or not
                          because I am using a VERY crude method to pull the time and date out of the
                          HTTP Response. If I were doing this for a real app I suppose some sort of
                          regular expression could be used as a more reliable method to pull the data
                          out of the resposne text.

                          Function GetOfficialUSTi me() As Boolean

                          On Error GoTo ErrHandler

                          Dim RetVal As Variant
                          Dim MyURL As String
                          Dim tim As String
                          Dim dat As String
                          Dim timStart As Integer
                          Dim datStart As Integer
                          Dim datEnd As Integer
                          Dim oHttpTest As Object

                          Set oHttpTest = CreateObject("M icrosoft.XMLHTT P")
                          MyURL = "http://www.time.gov/timezone.cgi?Ce ntral/d/-6"
                          oHttpTest.Open "POST", MyURL, False
                          oHttpTest.Send

                          If CLng(oHttpTest. Status) < 300 Then 'Response is OK
                          datStart = InStr(oHttpTest .responseText, "<td align=" & Chr(34) &
                          "center" & Chr(34) & "><font size=" & Chr(34) & "7" & Chr(34) & " color=" &
                          Chr(34) & "white" & Chr(34) & "><b>") + 116
                          datEnd = InStr(datStart, oHttpTest.respo nseText, "<br>")
                          timStart = InStr(oHttpTest .responseText, "<td align=" & Chr(34) &
                          "center" & Chr(34) & "><font size=" & Chr(34) & "7" & Chr(34) & " color=" &
                          Chr(34) & "white" & Chr(34) & "><b>") + 51

                          tim = Mid(oHttpTest.r esponseText, timStart, 8)
                          dat = Mid(oHttpTest.r esponseText, datStart, datEnd - datStart)
                          MsgBox "Time = " & tim & vbCrLf & "Date = " & dat
                          Else
                          RetVal = MsgBox("Status Code: " & oHttpTest.Statu s & vbCrLf & _
                          "Status Text: " & oHttpTest.statu sText & vbCrLf & vbCrLf & _
                          "Unexpected Response From Server" & vbCrLf & vbCrLf & _
                          "Press 'OK' To See Full Response in Web Browser",
                          vbExclamation + vbOKCancel, "Unexpected Server Error")
                          If RetVal = vbOK Then
                          If Dir("C:\HTTP_ER R.HTM") <> "" Then Kill "C:\HTTP_ERR.HT M"
                          Open "C:\HTTP_ERR.HT M" For Output As #1
                          Print #1, oHttpTest.respo nseText
                          Close #1
                          Application.Fol lowHyperlink "C:\HTTP_ERR.HT M"
                          End If
                          End If

                          Egress:
                          Set oHttpTest = Nothing
                          Exit Function

                          ErrHandler:
                          MsgBox Err.Description
                          Resume Egress
                          End Function

                          --
                          I don't check the Email account attached
                          to this message. Send instead to...
                          RBrandt at Hunter dot com


                          Comment

                          • rdemyan via AccessMonster.com

                            #14
                            Re: Get Internet Date/Time

                            Thanks, Rick.

                            I'll give it a try and report back on how it worked. I'll also try
                            substituting the NIST and Naval Observatory urls to see what happens.


                            Rick Brandt wrote:[color=blue][color=green]
                            >> Yeah, I've been wondering about this. Unfortunately, I am not very
                            >> knowledgable about the web.[/color]
                            >[quoted text clipped - 5 lines][color=green]
                            >>
                            >> Any thoughts on that or suggestions?[/color]
                            >
                            >Well basically if you can find any publicly available web service that
                            >serves the current time then you could make an HTTP request to that service.
                            >All that would be left would be to figure out how to parse the response.
                            >
                            >This example retrieves the date and (central) time from www.time.gov. At
                            >least it does for me. I make no guarantees whether it will work or not
                            >because I am using a VERY crude method to pull the time and date out of the
                            >HTTP Response. If I were doing this for a real app I suppose some sort of
                            >regular expression could be used as a more reliable method to pull the data
                            >out of the resposne text.
                            >
                            >Function GetOfficialUSTi me() As Boolean
                            >
                            >On Error GoTo ErrHandler
                            >
                            >Dim RetVal As Variant
                            >Dim MyURL As String
                            >Dim tim As String
                            >Dim dat As String
                            >Dim timStart As Integer
                            >Dim datStart As Integer
                            >Dim datEnd As Integer
                            >Dim oHttpTest As Object
                            >
                            >Set oHttpTest = CreateObject("M icrosoft.XMLHTT P")
                            >MyURL = "http://www.time.gov/timezone.cgi?Ce ntral/d/-6"
                            >oHttpTest.Op en "POST", MyURL, False
                            >oHttpTest.Se nd
                            >
                            >If CLng(oHttpTest. Status) < 300 Then 'Response is OK
                            > datStart = InStr(oHttpTest .responseText, "<td align=" & Chr(34) &
                            >"center" & Chr(34) & "><font size=" & Chr(34) & "7" & Chr(34) & " color=" &
                            >Chr(34) & "white" & Chr(34) & "><b>") + 116
                            > datEnd = InStr(datStart, oHttpTest.respo nseText, "<br>")
                            > timStart = InStr(oHttpTest .responseText, "<td align=" & Chr(34) &
                            >"center" & Chr(34) & "><font size=" & Chr(34) & "7" & Chr(34) & " color=" &
                            >Chr(34) & "white" & Chr(34) & "><b>") + 51
                            >
                            > tim = Mid(oHttpTest.r esponseText, timStart, 8)
                            > dat = Mid(oHttpTest.r esponseText, datStart, datEnd - datStart)
                            > MsgBox "Time = " & tim & vbCrLf & "Date = " & dat
                            >Else
                            > RetVal = MsgBox("Status Code: " & oHttpTest.Statu s & vbCrLf & _
                            > "Status Text: " & oHttpTest.statu sText & vbCrLf & vbCrLf & _
                            > "Unexpected Response From Server" & vbCrLf & vbCrLf & _
                            > "Press 'OK' To See Full Response in Web Browser",
                            >vbExclamatio n + vbOKCancel, "Unexpected Server Error")
                            > If RetVal = vbOK Then
                            > If Dir("C:\HTTP_ER R.HTM") <> "" Then Kill "C:\HTTP_ERR.HT M"
                            > Open "C:\HTTP_ERR.HT M" For Output As #1
                            > Print #1, oHttpTest.respo nseText
                            > Close #1
                            > Application.Fol lowHyperlink "C:\HTTP_ERR.HT M"
                            > End If
                            >End If
                            >
                            >Egress:
                            > Set oHttpTest = Nothing
                            >Exit Function
                            >
                            >ErrHandler:
                            > MsgBox Err.Description
                            > Resume Egress
                            >End Function
                            >[/color]

                            --
                            Message posted via AccessMonster.c om

                            Comment

                            • Rick Brandt

                              #15
                              Re: Get Internet Date/Time

                              rdemyan via AccessMonster.c om wrote:[color=blue]
                              > Thanks, Rick.
                              >
                              > I'll give it a try and report back on how it worked. I'll also try
                              > substituting the NIST and Naval Observatory urls to see what happens.[/color]

                              The naval observatory's time service actually sends back a much smaller respose
                              that would be easier to parse. It also just gives you several time zones in one
                              request rather than having you specify.


                              --
                              I don't check the Email account attached
                              to this message. Send instead to...
                              RBrandt at Hunter dot com


                              Comment

                              Working...