views:

291

answers:

8

I have made a demo small program that I want to deliver to my client so that he can run it for 5 times to check its functionality. It is not a big software for which I implement some serial-key functionality and make a trial software.

I want a simple solution which can restrict the use of the program more than 5 times or which can delete itself after its threshold limit.

One solution came in my mind. I make 4 .txt files through the same program and store them at diff. locations on the client computer and these files will store the number of times the program has been run. Each time the application starts, it checks all those files and if any file contain the number representing the threshold limit, it simply exit by saying that the threshold limit has been reached.

Is there any other more better solution, yet simple, to restrict the client from using it various times?

It would be even more better if the program gets deleted after its threshold limit.

+4  A: 

If you want it make really simpler, put a time check and don't allow client to run the code when the time has expired after say five days or one week from today

You can try below snippet

Calendar expiry = Calendar.getInstance();
expiry.set(2010, 1, 31,0,0); // Expire at 31 Jan 2010
Calendar now = Calendar.getInstance();
// If you don't trust client's clock, fetch time from some reliable time server
if( now.after(expiry)){
// Exit with proper expiry message
}
else
{ 
// let the customer enjoy your software
} 

You can check here on how to fetch time from a trusted time server.

Ravi Gupta
I think that can be breaked if the client sets his clock back every time he runs the sript ....Isn't it?
Yatendra Goel
Yes, but you can try to get the time from some reliable source on internet
Ravi Gupta
could you please tell me how to fetch time from some external source?
Yatendra Goel
Added the link in the answer :-)
Ravi Gupta
you could use the ntp client from apache commons : http://commons.apache.org/net/api/org/apache/commons/net/ntp/NTPUDPClient.html
Valentin Rocher
Have a look at what happened at vmware when they forgot to remove such code from a final release: http://www.vmhero.com/2008/08/12/esx-product-has-expired/
Thorbjørn Ravn Andersen
Sad, but I guess not everyone does the same mistake.
Ravi Gupta
any reason not to use: now.after(expiry) <--- more readable no?
Viktor Klang
@Viktor Edited code. Thanks
Ravi Gupta
@Ravi Could you please suggest me IP of a time server. I have been searching for a free time server with which I can get time but couldn't find any one.
Yatendra Goel
Did you tried looking up here: http://tf.nist.gov/tf-cgi/servers.cgi#
Ravi Gupta
Yes, I tried it various times but the browser couldn't open the site. May be the server is down temporarily or permanently.
Yatendra Goel
Try to run a sample program against these servers, it may be that these servers only accept time request and not other normal requests.
Ravi Gupta
I have done that too... The program is also not responding. So I think the servers are not working now.
Yatendra Goel
Maybe, but for the time being you can trust you user that they will not mess the clock and later on when you a get time server you can use it. The point is how much effort you wish to put in preventing excess use of your software ? What are the tradeoffs ?
Ravi Gupta
+2  A: 

Consider using Java Web Start to deploy your software with a JNLP file per customer with a customer specific, hard to guess, location. This allows you to do centralized management, and delete the JNLP when the time period is up.

Also ensure that a small jar is always uncached so the customer need to contact your server to be able to run.

Thorbjørn Ravn Andersen
Can I convert my standalone application to jnlp. If yes, then could you please tell me how?
Yatendra Goel
I liked your solution and @Ravi's solution. Acc. to you, which would be better solution to go with?
Yatendra Goel
Client's firewall is something you need to be aware of, if it blocks internet access of your program, both solutions will fail :-(
Ravi Gupta
That would be good for me because if internet access fails, then my program will also stop working as it access internet for working. :)
Yatendra Goel
If you use Netbeans it is very simple. The functionality is built right into the IDE. Eclipse has no such immediate support.
Thorbjørn Ravn Andersen
Yes, I use Netbeans. Can you tell me how to convert it into jnlp through Netbeans. Meanwhile I also search on Google for that.
Yatendra Goel
A: 

Instead of 4 files, have single file and write the number (number of times the client can use the demo version) to the file during installation. On every run check whether the file exists, decrement the number and write again to the same file.

If the file is not found or the value is zero exit the program.

Sri Kumar
+1  A: 

Let them try it via Remote Desktop or VNC.

Viktor Klang
I think this is often the simplest solution, keeping the program in-house, and sparing the client any installation pains.
jakobengblom2
+1  A: 

For windows applications, I do it in the following manner

I create a registry key inside my program, with the date it was used for the first time. This key is hidden in a field nammed with a non suggestive name and the value encripted;

I also store the last date it was used, to avoid the clock trick.

In my validation code, everytime I start the program, it checks the atual date and the date the program was used for the first time. If it is correct, I store too the last time the program was used. We have 3 cases for validating:

  1. If the atual date is bigger than the initial time, overlaping the demo period, the program isn't used anymore.

  2. If the computer date is smaller than the last time the program was used, the user tried to rewind the system clock. After this the program can't be used anymore

  3. The last case is when the system date is after the initial use date and before the expiration date. In this case, the program is allowed to be used.

    // This code is for system registry access public static Preferences userPref = Preferences.userRoot();

    // Write the registry userPref.put("keyName", "value");

    // Read the registry String read = userPref.get(key, "0");

marionmaiden
So, what happens when the customer runs this on a VM and before running it the first time creates a snapshot? When the product expires, to run it again, rollback the snapshot and run N more times.
Kevin Brock
A: 

Quickly this is what I think.

  1. Create a Data Structure like

class {

prop uid = HOSTNAME; prop MaxUsage = 5; prop AlreadyUsed = 5;

}

  1. Implement this class as Serializable, Write this file to disk without the HOSTNAME e.g. http://www.java2s.com/Code/Java/File-Input-Output/Serializerclass.htm

  2. Ship this serializable file with the application.

  3. When the application runs the first time write the property uid with the HOSTNAME of the host the app is running on. decrement the AlreadyUsed every time the app runs and save it to file.

  4. Every time the application runs check if the file is present, if not exit, if yes then check the uid has the correct HOSTNAME and that the number of Already used is not == 0

If you are using something Like JavaWebstart it will be very easy also.

Hope that helps your cause.

Shaaf
A: 

Give them a customer "key" and have the software ask a small servlet on your own web server whether the product is currently valid for the customer with this key.

Cheekysoft