Announcement

Collapse
No announcement yet.

WoW64 Plugin implementation

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WoW64 Plugin implementation

    Hi Forum, I need to include this code, based on AMS Expiration Example, in Startup Page.
    How I can use this correctly on both architectures 32\64bit?
    Thanks a lot!


    Code:
    -- Check if the OS is 64 bit
    b64Bit = System.Is64BitOS();
    
    if b64Bit then
    
    else
    
    end
    
    ------32Bit------
    
    -- Initialize variables
    days_left = 365;
    date_installed = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true);
    time_limit = 365; --the length of the trial period, in days
    
    -- Convert string value to number
    date_installed = String.ToNumber(date_installed);
    
    -- Was date_installed 0 (non-existent)?
    if date_installed == 0 then
    -- Value was nonexistent, create it
    Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ);
    else
    -- Update days_left
    days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
    end
    
    -- Are there days left?
    if days_left < 1 then
    -- There are not any days left, alert user and exit.
    Dialog.Message("Trial Period Over", "This software has expired");
    Application.Exit();
    end
    
    ------64Bit------
    
    -- Initialize variables
    days_left = 365;
    date_installed = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true, Wow64.KEY64);
    time_limit = 365; --the length of the trial period, in days
    
    -- Convert string value to number
    date_installed = String.ToNumber(date_installed);
    
    -- Was date_installed 0 (non-existent)?
    if date_installed == 0 then
    -- Value was nonexistent, create it
    Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ, Wow64.KEY64);
    else
    -- Update days_left
    days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
    end
    
    -- Are there days left?
    if days_left < 1 then
    -- There are not any days left, alert user and exit.
    Dialog.Message("Trial Period Over", "This software has expired");
    Application.Exit();
    end

  • #2


    https://forums.indigorose.com/forum/...=1557764304256

    Comment


    • #3
      Thanks herrin but I don't want Application.SaveValue. I prefer Registry.SetValue.
      On 64Bit systems I have problem with WoW6432Node so I use dedicated plugin.
      I would to use my code but I don't know the way to determine the appropriate cod for appropriate architecture.

      Unfortunately Application.SaveValue saves data into Indigo Rose Master Key, the reason I prefer Registry.SetValue.

      Thanks in advance for a MakeUp of my simple code.

      Comment


      • #4
        You already have workable code for each of the respective architectures. And System.Is64BitOS() returns boolean. So what's the problem?

        ie.
        Code:
        If (System.Is64BitOS()) then
             -- your x64 code
        else
             -- your x86 code
        end
        What exactly don't you understand?












        Comment


        • #5
          Excuse me Bio, I'm confused, too many if, than, end ...
          So is the following code correct?

          Code:
          -- Check if the OS is 64 bit
          b64Bit = System.Is64BitOS();
          if b64Bit then
          
          ------64Bit------
          
          -- Initialize variables
          days_left = 365;
          date_installed = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true, Wow64.KEY64);
          time_limit = 365; --the length of the trial period, in days
          
          -- Convert string value to number
          date_installed = String.ToNumber(date_installed);
          
          -- Was date_installed 0 (non-existent)?
          if date_installed == 0 then
          -- Value was nonexistent, create it
          Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ, Wow64.KEY64);
          else
          -- Update days_left
          days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
          end
          
          -- Are there days left?
          if days_left < 1 then
          -- There are not any days left, alert user and exit.
          Dialog.Message("Trial Period Over", "This software has expired");
          Application.Exit();
          end
          
          else
          
          ------32Bit------
          
          -- Initialize variables
          days_left = 365;
          date_installed = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true);
          time_limit = 365; --the length of the trial period, in days
          
          -- Convert string value to number
          date_installed = String.ToNumber(date_installed);
          
          -- Was date_installed 0 (non-existent)?
          if date_installed == 0 then
          -- Value was nonexistent, create it
          Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ);
          else
          -- Update days_left
          days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
          end
          
          -- Are there days left?
          if days_left < 1 then
          -- There are not any days left, alert user and exit.
          Dialog.Message("Trial Period Over", "This software has expired");
          Application.Exit();
          end
          end

          Comment


          • #6
            hi @BioHazard
            I honestly don't understand what the problem is.
            the example of TJ_Tigger (based on the Bruce code) not only does not write anything in HKEY_CURRENT_USER\Software\Indigo Rose\ACData
            but it is also cryptated (base64) therefore more secure than the one proposed by him

            regards

            Comment


            • #7
              Originally posted by herrin View Post
              hi @BioHazard
              I honestly don't understand what the problem is.
              The problem is that TJ_Tigger example doesn't consider Wow6432Node.
              So, cause of my poor skills, I asked for a simple code to include.
              Has you can see, I already blow my mind with a bunch of code lines.

              Anyway the code I previously posted doesn't work on 64bit.
              The error seem a wrong "end" on 64bit zone.

              This works instead


              Code:
              -- Check if the OS is 64 bit
              b64Bit = System.Is64BitOS();
              if b64Bit then
              
              ------64Bit------
              
              -- Initialize variables
              days_left = 365;
              date_installed = Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true, Wow64.KEY64);
              time_limit = 365; --the length of the trial period, in days
              
              -- Convert string value to number
              date_installed = String.ToNumber(date_installed);
              
              -- Was date_installed 0 (non-existent)?
              if date_installed == 0 then
              -- Value was nonexistent, create it
              Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ, Wow64.KEY64);
              else
              -- Update days_left
              days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
              end
              
              -- Are there days left?
              if days_left < 1 then
              -- There are not any days left, alert user and exit.
              Dialog.Message("Trial Period Over", "This software has expired");
              Application.Exit();
              end
              
              else
              
              ------32Bit------
              
              -- Initialize variables
              days_left = 365;
              date_installed = Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true);
              time_limit = 365; --the length of the trial period, in days
              
              -- Convert string value to number
              date_installed = String.ToNumber(date_installed);
              
              -- Was date_installed 0 (non-existent)?
              if date_installed == 0 then
              -- Value was nonexistent, create it
              Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ);
              else
              -- Update days_left
              days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
              end
              
              -- Are there days left?
              if days_left < 1 then
              -- There are not any days left, alert user and exit.
              Dialog.Message("Trial Period Over", "This software has expired");
              Application.Exit();
              end
              end
              end
              Do you confirm?
              Thanks

              Comment


              • #8
                are u sure?

                Click image for larger version

Name:	screen.PNG
Views:	129
Size:	31.8 KB
ID:	303330

                Comment


                • #9
                  I can confirm TJ's does work on Win X64, but must be run as Admin to write to Reg and SysWOW64 folder

                  Comment


                  • #10
                    herrin you are right, (indirectly TJ_Tigger too).
                    charliechaps, thanks for testing, Admin seems the problem.
                    So I can use only the 32bit code on both architectures.
                    If anyone has some "simple" suggestion, I'm here.
                    I'm a teacher, not a programmer, I make simple software for disabled in my school.
                    Thanks for all.

                    Comment


                    • #11
                      Originally posted by herrin View Post
                      I honestly don't understand what the problem is...
                      Mmm yes, agreed. At any rate, code samples left behind by TJ are usually first rate. And yes, there's sufficient logic in that particular example to adapt it to his personal requirements. The source of confusion though is because he doesn't quite yet understand how to recognize where control structures begin and end. Some patience is required for the newbies until they fully get their head around the basics, I guess. But Herrin is correct, AndrewX. Mastering basic control structures first, will make it easier for you to bend code samples to your specific needs.

                      But let's move on ...

                      Originally posted by AndrewX View Post
                      I'm confused, too many if, than, end ...
                      It helps if you start formatting your code correctly. Makes it easier to visualize a control structure to know where to position the 'end' statements. Is an 'optical' thing as much as a mental thing. So tab your code after initiating if/then statements, loops, etc. General rule-of-thumb is "tab do, after blue" ('end' statements are an exception). If doing it right, your final 'end' statement will always realign to the left margin.

                      So is the following code correct?
                      Depends on what you mean by 'correct'. If you mean, 'Does it do what I want, without returning errors?', then yes it's correct. But if you mean, 'Does it do the above AND avoid needless repetition to minimize overhead?', then the answer is, no. So you tell me. Does it meet this criteria? And have you run tests on both architectures? Did you experiment & tweak when encountering 'unexpected' results? What did you discover and learn about how to order 'end' statements, AndrewX?

                      If anyone has some "simple" suggestion...
                      Here's what I'd do with it. And is just one approach ...

                      The function System.Is64BitOS() returns a boolean result. No need to store in a variable.
                      Identify pointless repetition - axe what's not required.
                      Assign variables as 'local' whenever practicable. They usurp less overhead.
                      Format the code for efficacy in placement of 'end' statements.

                      ie.
                      Code:
                      local days_left = 365;
                      local time_limit = 365;
                      
                      if (System.Is64BitOS()) then    -->> INITIATE MAIN CONTROL STRUCTURE
                      
                          -- execute the x64 code here
                          local date_installed = String.ToNumber(Wow64.RegistryGetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true, Wow64.KEY64));
                          if date_installed == 0 then
                              Wow64.RegistrySetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ, Wow64.KEY64);
                          else
                              days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
                          end
                      
                      else    -->> OTHERWISE    
                          
                          -- execute the x86 code here
                          local date_installed = String.ToNumber(Registry.GetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", true));
                          if date_installed == 0 then
                              Registry.SetValue(HKEY_LOCAL_MACHINE, "Software\\My Application", "MyValue", System.GetDate(DATE_FMT_JULIAN), REG_SZ);
                          else
                              days_left = (date_installed + time_limit) - System.GetDate(DATE_FMT_JULIAN);
                          end
                                  
                      end    -->> CLOSE MAIN CONTROL STRUCURE
                      
                      if days_left < 1 then
                          Dialog.Message("Trial Period Over", "This software has expired");
                          Application.Exit();
                      end

                      This seems to work for me ...

                      x64 Test:


                      x86 Test:


                      Personally, I'd refine a things bit further by wrapping the common core as a function to be placed in Globals. And then call as required. (Example attached).
                      Attached Files

                      Comment


                      • #12
                        Excuse me Bio, but your example doesn't work for me.
                        I tried it, without any modification and with Admin Privileges.
                        Obviously Wow64 plugin enabled and included.
                        Tested on fresh copys of Win7 64 and Win10 64.
                        No Registry Keys written.
                        Excuse me again for time wasting.

                        Comment


                        • #13
                          Indeed. An oversight on my part. Just add the following line to the function in Globals (between Lines 4 & 5):
                          Code:
                          Wow64.RegistryCreateKey(HKEY_LOCAL_MACHINE, "Software\\My Application", Wow64.KEY64);
                          Sorry about that. Will function as expected now. (Modded demo is attached).

                          Nb.
                          ​​​​​​​Tested under Win7(x64) and WinXP(x86).
                          Works perfectly.
                          (Not yet tested under Win10).

                          Attached Files

                          Comment


                          • #14
                            And yes, finally it works.
                            Tested on Win10 x64 Win7 x64 and Win7 x86.
                            Only a question:
                            Why Wow64 plugin write in Software and not in Wow64Node\Software?

                            Finally, a PM for you.

                            Really appreciated!

                            Comment


                            • #15
                              alternative code for the final purpose, to determine the end of the use of the application
                              nothing will be written



                              Code:
                              [ATTACH]n303344[/ATTACH]

                              Comment

                              Working...
                              X