Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

detect a date change

How do you detect when the system date has changed?
0
millenisys
Asked:
millenisys
1 Solution
 
TchalkovCommented:
you can periodically compare system date with a global variable which contains previous date
0
 
mcriderCommented:
Do you mean something like someone changing the date backwards to get around a license??

If so, before you end your program, do this:

   SaveSetting "MyApp", "Startup", "Time", CStr(Now)


Then when you start your program do this:


Dim lDate As Date

If Not GetSetting("MyApp", "Startup", "Time", "0") = "0" Then
    lDate = GetSetting("MyApp", "Startup", "Time", "0")
    If DateDiff("s", lDate, Now) < 0 Then
        MsgBox "You have moved the date back!"
    End If
End If



Cheers!®©
0
 
Erick37Commented:
Windows sends the WM_TIMECHANGE message whenever the time or date is changed.  VB can catch this message if you subclass your form to intercept windows messages.  An example of how to do this is in this MS article:

"HOWTO: Build a Windows Message Handler with AddressOf in VB"

http://support.microsoft.com/support/kb/articles/q170/5/70.ASP

The article uses the WM_RBUTTONUP message as an example, but you will replace it with
Public Const WM_TIMECHANGE = &H1E

Note: If you use subclassing, do not pause the code or add breakpoints or VB will crash in the IDE.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
vindevogelCommented:
On the fly ??

Make a timer, interval = 1000

Sub Timer1_Timer
   Static vLastTime as single

   If Abs(vLastTime - Timer) > 1 Then
      MsgBox "You're messing with the time"
   End If
End Sub

Keep this program running, of course.

If you want to do it without running a program, or detecting it afterwards ... Then I don't know.
0
 
ndbCommented:
Comment for mcrider:
Your code should do perfectly.
But you better replace MyApp with a string that can't be related with your program because it is one of the first places where hackers will look for the timestamp.
0
 
mcriderCommented:
ndb,

<VBG> actually it was just an example... I store all of my keys and values in the registry as encrypted string... Can't read them, Got not clue what they do... <G>


Cheers!®©
0
 
millenisysAuthor Commented:
Thanks for all your help, I was hoping that NT (or 95/98) kept a setting in the registry.
0
 
mcriderCommented:
Thanks for the points, glad I could help!


Cheers!®©
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now