开发者

Windows datetime?

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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜