newbie2015
newbie2015

Reputation: 581

Add an expiry to win32 software using visual studio 2013

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.

Upvotes: 0

Views: 71

Answers (1)

Glapa
Glapa

Reputation: 800

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.

Upvotes: 0

Related Questions