-2

I am implementing a Trial Version of the software i have created, now i want to catch any change in the DateTime by the user.

I tried searching how to get bios system time but no luck in that so that is the only way to do it.

I think that i have to implement a hook in the windows to catch any change. How to do it, i have seen couple of codes which was very complicated for a junior programmer like me so if anybody could give a simplified example or at least explain how it's done.

ykh
  • 1,775
  • 3
  • 31
  • 57
  • I have found an event SystemEvents.TimeChanged but don't know how to use it if anyone can give me any ideas. – ykh Oct 15 '11 at 13:40
  • Put the tag of the language you are using. – xanatos Oct 15 '11 at 14:02
  • Let's say this: your program isn't running at the time of the event -> the event isn't triggered. The user kill your program, change the time, rerun your program. Done. – xanatos Oct 15 '11 at 14:03
  • That is why i wanted to add a listener that will run on start up and will be shown in task manager and it will listen to any change. – ykh Oct 16 '11 at 06:35
  • So they have to kill the listener and change your date? Or reboot, start the bios and change the time from there? Windows time and bios (computer) time are the same thing. – xanatos Oct 16 '11 at 06:39
  • So what do u suggest other than using the internet cause using the internet for our type of clients is hopeless and it will never work cause 90% and maybe even more don't have internet. – ykh Oct 16 '11 at 06:45
  • I have written my suggestion: use the update time of Windows updates and test it very much. Or desist. Or use running time of your program (so instead of 30 "solar" days, your program will work for 100 hours of use (you measure it using `System.Environment.TickCount`. That can't be changed by user) or it will work up to n times (so each time the user closes and relaunches your program it's one time)). Even this won't protect you if, for example, the user puts your program in a VM (read http://www.vmware.com/support/ws55/doc/ws_preserve_using_sshot.html) – xanatos Oct 16 '11 at 06:52

1 Answers1

3

You don't do it the way you want to do. It wouldn't work.

You check with an authoritative internet time server or something similar (or you put up a server of your with a web service that return the current time). If you don't know how to do it, you simply check http://tycho.usno.navy.mil/cgi-bin/timer.pl

I'll add that you can read here Prevent time-based copy protection circumvention? if you don't trust me.

I'll tell another strategy. I'm not sure it can work. It has many many problems (it runs on my machine, but I haven't tested it anywhere). It's slow (you should run it in its thread and if there is an error cause the thread to exit the program). I don't know if it's compatible. I don't know if low level users can run it. It looks at the list of upgrades for Windows and takes the most recent one date. If the user doesn't ever updates his windows, he will trick it.

Add a reference to C:\Windows\System32\wuapi.dll. It will generate an "interop" dll and add a reference to it.

using WUApiLib;

UpdateSession uSession = new UpdateSession();
IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
uSearcher.Online = false;
try
{
    ISearchResult sResult = uSearcher.Search("IsInstalled=1 OR IsInstalled=0");
    // This one!!!!
    var maxTime = sResult.Updates.OfType<IUpdate>().Max(p => p.LastDeploymentChangeTime);
}
catch (Exception ex)
{
    Console.WriteLine("Something went wrong: " + ex.Message);
} 

Oh... I was supposing you where using C# :-) If you are using C++ you can convert the code. The next time you'll learn to put the tag of the language.

Community
  • 1
  • 1
xanatos
  • 109,618
  • 12
  • 197
  • 280
  • The program i have developed doesn't contain any web services what so ever and i was asked to implement it this way so that is why i am looking for a way to check without the internet. – ykh Oct 15 '11 at 13:38
  • The code is not working and when i traced it, it goes to the ISearchResult line and then executes without going to the next line – ykh Oct 16 '11 at 06:43
  • @user733659 Wooops... I hadn't noticed your message. Retry now. As written it searched only for updates that were "pending" (so that the Windows Update knew of but that hadn't been installed) – xanatos Oct 26 '11 at 08:56