Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to detect that the system clock has been set backwards?

How to detect that the system clock has been set backwards?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
13 Posts 6 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Daniel Ferguson

    Check the date/time of important system files. If they are from the future, you know something is up. _____________________ "So in the interests of survival, they trained themselves to be agreeing machines instead of thinking machines. All their minds had to do was to discover what other people were thinking, and then they thought that, too." Breakfast of Champions, Kurt Vonnegut

    G Offline
    G Offline
    Geert Delmeiren
    wrote on last edited by
    #3

    Daniel Ferguson wrote: Check the date/time of important system files. Can you give some examples? Is it possible it could work from Win95 upto WinXP?

    J 1 Reply Last reply
    0
    • G Geert Delmeiren

      Daniel Ferguson wrote: Check the date/time of important system files. Can you give some examples? Is it possible it could work from Win95 upto WinXP?

      J Offline
      J Offline
      Jon Hulatt
      wrote on last edited by
      #4

      \winnt\system32\user32.dll get the last accessed time. Signature space for rent. Apply by email to....

      A G 2 Replies Last reply
      0
      • G Geert Delmeiren

        Hi, Does anyone have an idea (tips, links, code) how my app can detect that the system clock is set backwards? I want to know even when my app was not running at the time of change and/or the PC has been rebooted. Thanks.

        S Offline
        S Offline
        Steve S
        wrote on last edited by
        #5

        This might be a problem on PCs that use daylight saving, or on systems that sync with an external time source, such as a server or radio clock. I'd allow a margin of at least 2 hours to be a valid change, although I'm assuming you want to do some kind of expiry-time protection. Steve S [This signature space available for rent]

        G 1 Reply Last reply
        0
        • J Jon Hulatt

          \winnt\system32\user32.dll get the last accessed time. Signature space for rent. Apply by email to....

          A Offline
          A Offline
          Andreas Saurwein
          wrote on last edited by
          #6

          This wont work if updating access times is turned off. (registry hack, speeds up quite a bit) ...if you're under 8 or younger. Chris Maunder, the Lounge

          J 1 Reply Last reply
          0
          • S Steve S

            This might be a problem on PCs that use daylight saving, or on systems that sync with an external time source, such as a server or radio clock. I'd allow a margin of at least 2 hours to be a valid change, although I'm assuming you want to do some kind of expiry-time protection. Steve S [This signature space available for rent]

            G Offline
            G Offline
            Geert Delmeiren
            wrote on last edited by
            #7

            That was an issue I indeed already thought of. Nevertheless, thanks for the input.

            1 Reply Last reply
            0
            • A Andreas Saurwein

              This wont work if updating access times is turned off. (registry hack, speeds up quite a bit) ...if you're under 8 or younger. Chris Maunder, the Lounge

              J Offline
              J Offline
              Jon Hulatt
              wrote on last edited by
              #8

              This hack sounds cool. More info? Signature space for rent. Apply by email to....

              A 1 Reply Last reply
              0
              • J Jon Hulatt

                This hack sounds cool. More info? Signature space for rent. Apply by email to....

                A Offline
                A Offline
                Andreas Saurwein
                wrote on last edited by
                #9

                http://is-it-true.org/nt/registry/rtips71.shtml[^] ...if you're under 8 or younger. Chris Maunder, the Lounge

                1 Reply Last reply
                0
                • J Jon Hulatt

                  \winnt\system32\user32.dll get the last accessed time. Signature space for rent. Apply by email to....

                  G Offline
                  G Offline
                  Geert Delmeiren
                  wrote on last edited by
                  #10

                  I don't think this will work. The last accessed timestamp of the file user32.dll is updated with a date of the past, when you set backwards the clock. But you can't check that. The computer thinks 'now' is that date in the past. Some more details about my question: Time line: A1 < A2 < X < E < Y My App is started at A1 end stopped at A2. My app informs the user that his license will expire at E. At time Y the user does the following: - he sets back the clock to X - he starts up my app How can my app know - the computer ever ran at Y (>E)? - the license is expired

                  1 Reply Last reply
                  0
                  • G Geert Delmeiren

                    Hi, Does anyone have an idea (tips, links, code) how my app can detect that the system clock is set backwards? I want to know even when my app was not running at the time of change and/or the PC has been rebooted. Thanks.

                    P Offline
                    P Offline
                    Phil J Pearson
                    wrote on last edited by
                    #11

                    Think about it from another direction: Why not record the time each time your app exits (keep it in a registry key or a hidden file or something of the sort). When your app starts compare the current time with the last-exit time. If the last-exit time appears to be in the future someone may be cheating. Just remember to allow for DST as someone else suggested.


                    The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).

                    G 1 Reply Last reply
                    0
                    • P Phil J Pearson

                      Think about it from another direction: Why not record the time each time your app exits (keep it in a registry key or a hidden file or something of the sort). When your app starts compare the current time with the last-exit time. If the last-exit time appears to be in the future someone may be cheating. Just remember to allow for DST as someone else suggested.


                      The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).

                      G Offline
                      G Offline
                      Geert Delmeiren
                      wrote on last edited by
                      #12

                      The scenario you suggest fails in the following case: Time line: A1 < A2 < X < E < Y My App is started at A1 end stopped at A2. My app informs the user that his license will expire at E. At time Y the user does the following: - he sets back the clock to X - he starts up my app When my app starts A2 < X, so it doesn't detect any cheating. How can my app know - the computer ever ran at Y (>E)? - the license is expired

                      A 1 Reply Last reply
                      0
                      • G Geert Delmeiren

                        The scenario you suggest fails in the following case: Time line: A1 < A2 < X < E < Y My App is started at A1 end stopped at A2. My app informs the user that his license will expire at E. At time Y the user does the following: - he sets back the clock to X - he starts up my app When my app starts A2 < X, so it doesn't detect any cheating. How can my app know - the computer ever ran at Y (>E)? - the license is expired

                        A Offline
                        A Offline
                        Andreas Saurwein
                        wrote on last edited by
                        #13

                        a) examine the eventlog - events there are in chronological order. b) write to eventlog your own entries. c) examine registry entries. booting leaves trails in registry. hint: RegQueryInfoKey() combine methods. ...if you're under 8 or younger. Chris Maunder, the Lounge

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups