I have created a program with a 30 day trial period in VB.Net. The program saves the time in the registry that the program was first launched and also the time is was used last. From that I calculate if the trial is still valid.
The problem is, the only place in the registry that a non-admin user can access is the HKEY_LOCAL_USER key. I need to implem开发者_如何学编程ent the trial for all users, otherwise a user can just use a new account and that would reset the trial.
Where can I save this information so that a user without admin rights can read and write from that location? I also want to save it in a place that the average user can't find too easily and delete the file that would reset the trial.
Thanks
I am not sure anyone has found a definitive answer for this. The only way is to store the data with you and not with the client - so do a web call on installation, and on every startup, and store the data on your server.
Which, unless you have an especially serious problem, is very OTT.
Short of that, encrypt and save the information on a file in the install directory. Encrypting it should make sure that the value cannot be changed, and if the file does not exist then do not allow access.
But it all depends how critical the trial period is.
Save the needed data in binary (DateTime.Now.Ticks
is System.Int64
;) ) and inflate it with redundant data and make a checksum field. On load check the checksum field and if it is wrong-the data has been tampered with so kill the trial period. You could also save the data in a file next to your application to avoid using the registry ( both for cross-platform compatibility and avoiding the required admin privileges )
HKEY_LOCAL_MACHINE is for all users but the user installing your app must have admin privileges.
My problem was actually where to save data that all users can access (read and write).
In Win 7 this can get tricky. I found this article on code project that explains how this can be achieved for folders.
I then read a file and save values in the registry as suggested by Kenny above.
If somebody has a better method, please share it.
精彩评论