0

Hi I have made a software which now I have to send to a colleague of mine. However I need to add an expiry so that the software stops running after 10 hours of total use. I don't know how to begin to go about this challenge.

Can you direct me to some documentation which can guide me in this regard.

UPDATE

I now have coded so that the application records total amount of time the application is running. But how do I save the value and update it for the next time the application runs The value should be saved even after the system reboots. And it should not even be accessible to the user to tamper with.

leppie
  • 115,091
  • 17
  • 196
  • 297
newbie2015
  • 581
  • 5
  • 29
  • http://www.cplusplus.com/reference/chrono/ – James Picone Nov 27 '15 at 06:46
  • @JamesPicone Hi I got the part about recording the amount of time the application runs at one go. But now I need to register those values and update them after further use. I don't want to keep it as 7 days or 14 days trial. I need it to be depending on number of hours the application is used. – newbie2015 Nov 27 '15 at 09:41
  • There's nothing you can do to absolutely prevent the user from tampering with the value saved on his computer. You could save the value on a different computer (over the Internet, for example), but then you'd run into the problem that you can't prevent the user from tampering with your program. – Ross Ridge Nov 27 '15 at 09:47
  • It's possible with some kind of encryption (e.g. AES or event simple one-time pad) – Glapa Nov 27 '15 at 09:49
  • so then I simply save it on the local computer in a log/text file with encrypted time stamp and details? – newbie2015 Nov 27 '15 at 10:02
  • @newbie2015 look at my answer. Still as I wrote below the code. File should be hidden by attribute (as hidden file) or/and in place where user won't look for it (e.g. C:\Windows, %appdata% folder). – Glapa Nov 27 '15 at 10:06
  • Be aware that **any software-only protection** mechanism can easily be circumvented by installing on another machine, or, better, by restoring a system image to start afresh when the user wants to. –  Nov 27 '15 at 10:45

1 Answers1

0

Easiest way to achieve that is to save that value to file. You can use some encryption methods to prevent reading it by user.

Simple code could be like that:

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  int secretKey = 123; //any value would do the trick
  unsigned daysUsed = 0;
  ifstream fIn;
  fIn.open("tm");
  if (fIn.is_open())
  {
      fIn >> daysUsed;
      daysUsed ^= secretKey;
      fIn.close();
  }

  //validate days here

  ofstream fOut;
  fOut.open("tm", std::ofstream::out | std::ofstream::trunc); // you can add binary flag if you want too
  fOut << (++daysUsed ^ secretKey);
  fOut.close();
  return 0;
}

It use simplest possible encription as example. I advise you to use some more advanced options e.g. AES. User can always delete your file but if you put it somewhere when user won't look for it it's the best option I guess. You can try registry entry too.

Glapa
  • 790
  • 10
  • 20
  • An easy hack is to search for all files dated after the first execution of the program. Registry is safer, but a before/after comparison is still possible. First hit of a web lookup: https://www.raymond.cc/blog/tracking-registry-and-files-changes-when-installing-software-in-windows/ –  Nov 27 '15 at 10:53