使用visual studio 2013为win32软件添加到期日期

时间:2015-11-27 06:40:17

标签: c++ trialware content-expiration

您好我已经制作了一个软件,现在我必须发送给我的同事。但是我需要添加一个到期日,以便软件在总使用10小时后停止运行。我不知道如何开始应对这一挑战。

你能指导我一些可以指导我这方面的文件。

更新

我现在已编码,以便应用程序记录应用程序运行的总时间。但是如何保存值并在下次运行应用程序时更新它 即使在系统重新启动后,也应保存该值。并且用户甚至不应该访问它来篡改。

1 个答案:

答案 0 :(得分:0)

实现这一目标的最简单方法是将该值保存到文件中。 您可以使用一些加密方法来防止用户阅读它。

简单的代码可能是这样的:

#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;
}

它使用最简单的编码作为例子。我建议你使用一些更高级的选项,例如AES。用户可以随时删除您的文件,但如果您将其放在某个地方,当用户不会查找它时,我猜这是最好的选择。您也可以尝试注册表项。