Incrementing date to implement trial period using Inno Setup












1















I am using Inno Setup compiler to create an installer set up for my software. The installer adds a timestamp to the Windows registry during the first installation. When the software is reinstalled, it checks the saved timestamp in Windows registry and if it is more than 90 days from the current date then it should stop the installation? so I am forcing the user to use the software only for 90 days.



I am trying to add 90 days to the current datetime for comparison. There is no option to do this in the datatype TSystemTime. I can add days to a TDateTime variable, but I can't use that variable in the Inno Setup script.



This is my code



function InitializeSetup(): Boolean;
var
InstallDatetime: string;
begin
if RegQueryStringValue(HKLM, 'SoftwareCompanyPlayerSettings', 'DateTimeInstall', InstallDatetime) then
{ I want to add 90 days before comparison }
Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
if not result then
MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
Result := True;
end;


I have seen a similar example on Stack Overflow. They have used a constant to compare the datetime. Instead, I am adding 90 days to my saved installation datetime.



Any help will be much appreciated.










share|improve this question





























    1















    I am using Inno Setup compiler to create an installer set up for my software. The installer adds a timestamp to the Windows registry during the first installation. When the software is reinstalled, it checks the saved timestamp in Windows registry and if it is more than 90 days from the current date then it should stop the installation? so I am forcing the user to use the software only for 90 days.



    I am trying to add 90 days to the current datetime for comparison. There is no option to do this in the datatype TSystemTime. I can add days to a TDateTime variable, but I can't use that variable in the Inno Setup script.



    This is my code



    function InitializeSetup(): Boolean;
    var
    InstallDatetime: string;
    begin
    if RegQueryStringValue(HKLM, 'SoftwareCompanyPlayerSettings', 'DateTimeInstall', InstallDatetime) then
    { I want to add 90 days before comparison }
    Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
    if not result then
    MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
    Result := True;
    end;


    I have seen a similar example on Stack Overflow. They have used a constant to compare the datetime. Instead, I am adding 90 days to my saved installation datetime.



    Any help will be much appreciated.










    share|improve this question



























      1












      1








      1


      2






      I am using Inno Setup compiler to create an installer set up for my software. The installer adds a timestamp to the Windows registry during the first installation. When the software is reinstalled, it checks the saved timestamp in Windows registry and if it is more than 90 days from the current date then it should stop the installation? so I am forcing the user to use the software only for 90 days.



      I am trying to add 90 days to the current datetime for comparison. There is no option to do this in the datatype TSystemTime. I can add days to a TDateTime variable, but I can't use that variable in the Inno Setup script.



      This is my code



      function InitializeSetup(): Boolean;
      var
      InstallDatetime: string;
      begin
      if RegQueryStringValue(HKLM, 'SoftwareCompanyPlayerSettings', 'DateTimeInstall', InstallDatetime) then
      { I want to add 90 days before comparison }
      Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
      if not result then
      MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
      Result := True;
      end;


      I have seen a similar example on Stack Overflow. They have used a constant to compare the datetime. Instead, I am adding 90 days to my saved installation datetime.



      Any help will be much appreciated.










      share|improve this question
















      I am using Inno Setup compiler to create an installer set up for my software. The installer adds a timestamp to the Windows registry during the first installation. When the software is reinstalled, it checks the saved timestamp in Windows registry and if it is more than 90 days from the current date then it should stop the installation? so I am forcing the user to use the software only for 90 days.



      I am trying to add 90 days to the current datetime for comparison. There is no option to do this in the datatype TSystemTime. I can add days to a TDateTime variable, but I can't use that variable in the Inno Setup script.



      This is my code



      function InitializeSetup(): Boolean;
      var
      InstallDatetime: string;
      begin
      if RegQueryStringValue(HKLM, 'SoftwareCompanyPlayerSettings', 'DateTimeInstall', InstallDatetime) then
      { I want to add 90 days before comparison }
      Result := CompareStr(GetDateTimeString('yyyymmdd', #0,#0), InstallDatetime) <= 0;
      if not result then
      MsgBox('This Software trial period is over. The Program will not install.', mbError, MB_OK);
      Result := True;
      end;


      I have seen a similar example on Stack Overflow. They have used a constant to compare the datetime. Instead, I am adding 90 days to my saved installation datetime.



      Any help will be much appreciated.







      inno-setup pascalscript






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 15:46









      Martin Prikryl

      91.1k22180385




      91.1k22180385










      asked Jan 3 at 14:33









      Vimal DavidVimal David

      158315




      158315
























          1 Answer
          1






          active

          oldest

          votes


















          1














          To increment TSystemTime, check performing Arithmetic on SYSTEMTIME.



          Though it would probably be difficult to implement 128-bit arithmetic in Inno Setup.





          Alternatively, you can implement it on your own:





          procedure IncDay(var Year, Month, Day: Integer);
          var
          DIM: Integer;
          begin
          Inc(Day);
          case Month of
          1, 3, 5, 7, 8, 10, 12: DIM := 31;
          2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
          DIM := 29
          else
          DIM := 28;
          4, 6, 9, 11: DIM := 30;
          end;
          if Day > DIM then
          begin
          Inc(Month);
          Day := 1;
          if Month > 12 then
          begin
          Inc(Year);
          Month := 1;
          end;
          end;
          end;

          procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
          begin
          while Days > 0 do
          begin
          IncDay(Year, Month, Day);
          Dec(Days);
          end;
          end;

          function IncDaysStr(S: string; Days: Integer): string;
          var
          Year, Month, Day: Integer;
          begin
          Year := StrToInt(Copy(S, 1, 4));
          Month := StrToInt(Copy(S, 5, 2));
          Day := StrToInt(Copy(S, 7, 2));
          IncDays(Year, Month, Day, Days);
          Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
          end;


          Use it like:



          result :=
          CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;





          share|improve this answer


























          • I am getting the following error 'Unknown identifier 'Inc'

            – Vimal David
            Jan 3 at 16:21








          • 1





            Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

            – Martin Prikryl
            Jan 3 at 16:30











          • I have used the Unicode version of Inno Setup and its working now.

            – Vimal David
            Jan 3 at 16:58












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024343%2fincrementing-date-to-implement-trial-period-using-inno-setup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          To increment TSystemTime, check performing Arithmetic on SYSTEMTIME.



          Though it would probably be difficult to implement 128-bit arithmetic in Inno Setup.





          Alternatively, you can implement it on your own:





          procedure IncDay(var Year, Month, Day: Integer);
          var
          DIM: Integer;
          begin
          Inc(Day);
          case Month of
          1, 3, 5, 7, 8, 10, 12: DIM := 31;
          2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
          DIM := 29
          else
          DIM := 28;
          4, 6, 9, 11: DIM := 30;
          end;
          if Day > DIM then
          begin
          Inc(Month);
          Day := 1;
          if Month > 12 then
          begin
          Inc(Year);
          Month := 1;
          end;
          end;
          end;

          procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
          begin
          while Days > 0 do
          begin
          IncDay(Year, Month, Day);
          Dec(Days);
          end;
          end;

          function IncDaysStr(S: string; Days: Integer): string;
          var
          Year, Month, Day: Integer;
          begin
          Year := StrToInt(Copy(S, 1, 4));
          Month := StrToInt(Copy(S, 5, 2));
          Day := StrToInt(Copy(S, 7, 2));
          IncDays(Year, Month, Day, Days);
          Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
          end;


          Use it like:



          result :=
          CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;





          share|improve this answer


























          • I am getting the following error 'Unknown identifier 'Inc'

            – Vimal David
            Jan 3 at 16:21








          • 1





            Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

            – Martin Prikryl
            Jan 3 at 16:30











          • I have used the Unicode version of Inno Setup and its working now.

            – Vimal David
            Jan 3 at 16:58
















          1














          To increment TSystemTime, check performing Arithmetic on SYSTEMTIME.



          Though it would probably be difficult to implement 128-bit arithmetic in Inno Setup.





          Alternatively, you can implement it on your own:





          procedure IncDay(var Year, Month, Day: Integer);
          var
          DIM: Integer;
          begin
          Inc(Day);
          case Month of
          1, 3, 5, 7, 8, 10, 12: DIM := 31;
          2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
          DIM := 29
          else
          DIM := 28;
          4, 6, 9, 11: DIM := 30;
          end;
          if Day > DIM then
          begin
          Inc(Month);
          Day := 1;
          if Month > 12 then
          begin
          Inc(Year);
          Month := 1;
          end;
          end;
          end;

          procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
          begin
          while Days > 0 do
          begin
          IncDay(Year, Month, Day);
          Dec(Days);
          end;
          end;

          function IncDaysStr(S: string; Days: Integer): string;
          var
          Year, Month, Day: Integer;
          begin
          Year := StrToInt(Copy(S, 1, 4));
          Month := StrToInt(Copy(S, 5, 2));
          Day := StrToInt(Copy(S, 7, 2));
          IncDays(Year, Month, Day, Days);
          Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
          end;


          Use it like:



          result :=
          CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;





          share|improve this answer


























          • I am getting the following error 'Unknown identifier 'Inc'

            – Vimal David
            Jan 3 at 16:21








          • 1





            Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

            – Martin Prikryl
            Jan 3 at 16:30











          • I have used the Unicode version of Inno Setup and its working now.

            – Vimal David
            Jan 3 at 16:58














          1












          1








          1







          To increment TSystemTime, check performing Arithmetic on SYSTEMTIME.



          Though it would probably be difficult to implement 128-bit arithmetic in Inno Setup.





          Alternatively, you can implement it on your own:





          procedure IncDay(var Year, Month, Day: Integer);
          var
          DIM: Integer;
          begin
          Inc(Day);
          case Month of
          1, 3, 5, 7, 8, 10, 12: DIM := 31;
          2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
          DIM := 29
          else
          DIM := 28;
          4, 6, 9, 11: DIM := 30;
          end;
          if Day > DIM then
          begin
          Inc(Month);
          Day := 1;
          if Month > 12 then
          begin
          Inc(Year);
          Month := 1;
          end;
          end;
          end;

          procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
          begin
          while Days > 0 do
          begin
          IncDay(Year, Month, Day);
          Dec(Days);
          end;
          end;

          function IncDaysStr(S: string; Days: Integer): string;
          var
          Year, Month, Day: Integer;
          begin
          Year := StrToInt(Copy(S, 1, 4));
          Month := StrToInt(Copy(S, 5, 2));
          Day := StrToInt(Copy(S, 7, 2));
          IncDays(Year, Month, Day, Days);
          Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
          end;


          Use it like:



          result :=
          CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;





          share|improve this answer















          To increment TSystemTime, check performing Arithmetic on SYSTEMTIME.



          Though it would probably be difficult to implement 128-bit arithmetic in Inno Setup.





          Alternatively, you can implement it on your own:





          procedure IncDay(var Year, Month, Day: Integer);
          var
          DIM: Integer;
          begin
          Inc(Day);
          case Month of
          1, 3, 5, 7, 8, 10, 12: DIM := 31;
          2: if (Year mod 4 = 0) and ((Year mod 100 <> 0) or (Year mod 400 = 0)) then
          DIM := 29
          else
          DIM := 28;
          4, 6, 9, 11: DIM := 30;
          end;
          if Day > DIM then
          begin
          Inc(Month);
          Day := 1;
          if Month > 12 then
          begin
          Inc(Year);
          Month := 1;
          end;
          end;
          end;

          procedure IncDays(var Year, Month, Day: Integer; Days: Integer);
          begin
          while Days > 0 do
          begin
          IncDay(Year, Month, Day);
          Dec(Days);
          end;
          end;

          function IncDaysStr(S: string; Days: Integer): string;
          var
          Year, Month, Day: Integer;
          begin
          Year := StrToInt(Copy(S, 1, 4));
          Month := StrToInt(Copy(S, 5, 2));
          Day := StrToInt(Copy(S, 7, 2));
          IncDays(Year, Month, Day, Days);
          Result := Format('%.4d%.2d%.2d', [Year, Month, Day]);
          end;


          Use it like:



          result :=
          CompareStr(GetDateTimeString('yyyymmdd', #0,#0), IncDaysStr(InstallDatetime, 90)) <= 0;






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 21:12

























          answered Jan 3 at 15:43









          Martin PrikrylMartin Prikryl

          91.1k22180385




          91.1k22180385













          • I am getting the following error 'Unknown identifier 'Inc'

            – Vimal David
            Jan 3 at 16:21








          • 1





            Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

            – Martin Prikryl
            Jan 3 at 16:30











          • I have used the Unicode version of Inno Setup and its working now.

            – Vimal David
            Jan 3 at 16:58



















          • I am getting the following error 'Unknown identifier 'Inc'

            – Vimal David
            Jan 3 at 16:21








          • 1





            Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

            – Martin Prikryl
            Jan 3 at 16:30











          • I have used the Unicode version of Inno Setup and its working now.

            – Vimal David
            Jan 3 at 16:58

















          I am getting the following error 'Unknown identifier 'Inc'

          – Vimal David
          Jan 3 at 16:21







          I am getting the following error 'Unknown identifier 'Inc'

          – Vimal David
          Jan 3 at 16:21






          1




          1





          Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

          – Martin Prikryl
          Jan 3 at 16:30





          Make sure you are using Unicode version of Inno Setup. Or replace Inc(X) with X := X + 1. Though you should use the Unicode version anyway.

          – Martin Prikryl
          Jan 3 at 16:30













          I have used the Unicode version of Inno Setup and its working now.

          – Vimal David
          Jan 3 at 16:58





          I have used the Unicode version of Inno Setup and its working now.

          – Vimal David
          Jan 3 at 16:58




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54024343%2fincrementing-date-to-implement-trial-period-using-inno-setup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'