Is it possible to find whether the current system date is changed or not with VB6.0 code?All i want to do is to prohibit the user from changing the system time.How can i do that?
I'd say that as long as the application is running, you could track a couple of things that might help. For instance, there is a"tick count" that indicates the number of times an internal clock has "ticked" since... um, either midnight, or system start-up, I forget which. You could keep track of that, and compare it with the current system time. If they suddenly get 'way out of synch, bingo!
You could also detect quite easily if the time goes
backward, in which case it
must have been altered. (
Unless the user really is going backward in time, but that's probably outside the scope of this discussion). This could include recording the time when your program is closed, and checking the time hasn't gone backward at start-up.
Of course there are things one probably should keep in mind...
- If it's the user's PC, then who are you to tell them what they can't do do it?
- Windows does sometimes have delays (no, really!) so the fact that the time skips a bit between checks should not be taken as significant. In other words, if you have a timer set up to run every 30 seconds, and suddenly find that the time has changed 5 minutes instead, that might just mean the system was busy for a while.
- Windows may have been configured to automatically synchronise the system time with some server somewhere. Which could cause the time to unexpectedly shift in either "direction". You don't (I assume) want your software to suddenly stop and accuse the user of perfidy for no apparent reason.
- Two words... Daylight Saving.
- You probably should look into Windows "policies". I think Windows can be set up to prevent the user changing the time. (See point 1.)
P.S. Um... actually, I think there's probably a message Windows sends out to all running apps to notify them the system time was changed. So you might just watch that.