ybe
Posts: 14
Joined: Fri Oct 09, 2020 9:27 am

Registry parameter settings

Wed Jun 02, 2021 9:25 am

Hello

I'm using Advanced Installer to install my application and I have set up registry for my application through Advanced Installer.

I have a Key called 'Java' and it contains an Integer value called 'max memory'. The value of 'max memory' is set to '4000', which means that if it's changed, it will reset to 4000 when upgrading.

Is there any simple way of resetting it only if it's higher than the changed value? Meaning the highest value always wins. If it's changed to something greater than 4000 then it should keep the change, and if it's changed to something lower than 4000 then it should reset to 4000.

Kind regards
Ybe

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Registry parameter settings

Wed Jun 02, 2021 5:15 pm

Hello Ybe,
Is there any simple way of resetting it only if it's higher than the changed value?
There is indeed a way, but not quite "simple".

In order to achieve this, we can proceed as it follows:

- first of all, we need to give the value of the registry entry through a property.

With that being said, please go to "Properties" page (if you are on the latest version of Advanced Installer - else go to "Install Parameters" page) and create a property for your value, e.g.:

Name: MEMORY
Value: 4000


- in "Registry" page, we need to give the value to our node through the above property, e.g.:
memory.png
memory.png (30.1KiB)Viewed 8920 times

Let's say the first version is now installed. When building the second version, we would need to:

- create a registry search (in the "Search" page) that will retrieve the raw value from our node, e.g.:
regvalue.png
regvalue.png (34.13KiB)Viewed 8920 times

- we will then need to create a set property custom action that will set the value of our MEMORY property to the value of the search property only if the search property has a value > 4000
setprop.png
setprop.png (121.17KiB)Viewed 8920 times


Basically, here is what will be happening: during the upgrade, the first thing to execute will be the search for our value. The property assigned to the search (e.g. RESULT_PROPERTY) will have the value of the node (in our case, let's say this would be 5000 - meaning that the user manually changed it from 4000 to 5000).

After that, the "Set Property" custom action will come into play.

In order to manipulate the value of the registry node, we will need to manipulate the value of the property that holds its' value (in our case, the MEMORY prop) - this being the reason why I have mentioned we need to offer the value through a property (above).

Through this "Set property" custom action, we will set the value of the MEMORY property to the value of the search property (RESULT_PROPERTY) only if RESULT_PROPERTY > 4000.

Else, the "Set property" custom action should no longer execute and thus the node should be reset to its normal value (i.e. 4000).

Hope this helps.

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

ybe
Posts: 14
Joined: Fri Oct 09, 2020 9:27 am

Re: Registry parameter settings

Fri Jun 04, 2021 1:15 pm

Hello Catalin,

First of all thank you for the very nice and detailed answer, that made it very easy to follow.

Just to be clear, I'm using Advanced Installer 17.0.

The solution you've suggested works perfectly when I set the Registry Value to String > Replace existing value like in your example. However as I wrote in the initial question, my Registry Value is an Integer, not a String. For some odd reason it does not work when I set the Registry Value to Integer even though everything else is exactly how you showed me to do it.

So here is what I did:

1. I introduced a new property in my Install Parameters
Property.PNG
Property.PNG (13.02KiB)Viewed 8910 times

2. In Registry I use the new property in the Data field og the Registry Value. Note that th type is Integer, not String
reg.PNG
reg.PNG (60.3KiB)Viewed 8899 times

3. I created a Registry Search (in the "Search" page) that retrieves the raw value from the node
t.PNG
t.PNG (34.31KiB)Viewed 8910 times

4.In the end I create a "Set installer property"-custom action that sets my 'JvmMx' property to the value of the search property only if the search property has a value > 4096
(I can't attatch more images, I will send it in another reply below)

I've installed the first version with this fix and then while on the first version changed my JvmMx Registry Value to 5000 in my Registry Editor. Then I upgraded to the second version, and it still resets to 4096.

Kind regards
Ybe
Last edited by ybe on Fri Jun 04, 2021 2:38 pm, edited 4 times in total.

ybe
Posts: 14
Joined: Fri Oct 09, 2020 9:27 am

Re: Registry parameter settings

Fri Jun 04, 2021 1:16 pm

Here is the missing custom action image from the previous answer
hello.PNG
hello.PNG (42.56KiB)Viewed 8908 times

Catalin
Posts: 6509
Joined: Wed Jun 13, 2018 7:49 am

Re: Registry parameter settings

Tue Jun 08, 2021 6:35 pm

Hello Ybe,

Thank you for your followup on this.

I have run some tests with the registry being set as an integer and I could indeed reproduce the behavior.

This happens because your condition is not quite correct.

In case of a REG_DWORD registry entry, the search will return a result as it follows:

#4096

instead of:

4096

However, even if we use a correct condition, the property will be set to the changed value (e.g. #5000 or any other higher value) which will make the registry entry being rewritten as a string.

Here would be some solutions to that:

1. add the registry entry as a string - depending on your scenario, this shouldn't make much of a difference - and use the approach I have given above

2. use a custom action that will retrieve the value of the registry entry, compare it to 4096 and then set the property accordingly. With this, we can be more precise with the value of the registry, retrieving only the integer without the hashtag and therefore the registry will be rewritten as an integer.

For instance, in my sample I have used an inline PowerShell script custom action.

It can look something similar to this:

Code: Select all

$memory = (get-itemproperty -path "HKLM:\SOFTWARE\Your Company\Your Application" -name Memory).Memory

if($memory -gt 4096){
AI_SetMsiProperty MEMORY $memory
}
Where:

- Memory is the name of my registry entry

- MEMORY is the name of the property used to create the registry entry

We need to take into consideration the bitness of our setup, though. For instance, on my 64-bit machine, the registry is actually written in the WOW6432Node because the process (the setup) is of 32-bit type.
RegistryRedirection.png
RegistryRedirection.png (118.88KiB)Viewed 8879 times

This will be automatically handled if the setup is of 32-bit and the platform used for PowerShell is set to 32-bit.

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”