I am working on a business related program, so I need to know if system date is correct -synced- with remote server. How do you do that in vb .NET winforms?
P.S: In addition, is there any way to raise some event when system clock changed to prevent hacks? I don’t want users to change local date after logging in their account.
Thanks in advance.
You will need to verify the clock with an external server and accept it if it is within a certain tolerance. All clocks are wrong by some degree. Usually a webservice on a server somewhere is enough, but there are many free NTP-services. Note however it would take me 5 minutes to bypass that, so for more security you need to use SSL (HTTPS) (makes man-in-the-middle attacks impossible).
Note however:
If you want to know when a user changes the clock simply set up a thread to loop with a 60 second Thread.Sleep(60000). Then check current DateTime against the one 60 seconds ago. It should always be 60 seconds -/+ 1 seconds since last check. (+/- 1 second is to compensate for delays like app hanging slightly as timer is executing, etc)
I threw together a quick example:
EDIT: Sorry, first sample was in C#. Redone it in VB.Net.