davidjhomer
Posts: 55
Joined: Wed Jun 08, 2016 3:58 pm
Contact: Website Facebook Skype Twitter

Setting properties to an empty value for the registry

Hello,

We have a registry key that we want to store by default with a blank value - but that the user can change manually using Regedit.... what is the preferred solution for this?

What we tried...

1. We create a property called SCHEDULER_CLIENTCERTIFICATETHUMBPRINT and have to set it to "-" because blank values aren't allowed

2. We perform a Search to check HKEY_LOCAL_MACHINE\SOFTWARE\CENTREL Solutions\XIA Configuration Scheduler\ClientCertificateThumbprint and put the value into SCHEDULER_CLIENTCERTIFICATETHUMBPRINT

3. We restore the value in the SCHEDULER_CLIENTCERTIFICATETHUMBPRINT value in the registry


The problem is this is...

1. In step one we are forced to set the property to a non empty value such as "-" or "NOT SET" which is a bit rubbish and is confusing for the user - we just want it blank.

2. The registry values cannot be configured to be set on First Install Only so if we set the registry value to blank directly (without using searches and properties) it is overwritten with a blank value every time an upgrade is performed.

3. If we don't set the registry value at all then the user has to manually create the registry value which isn't ideal - we'd prefer the user has an existing empty value that they can configure.


Thanks,


Dave
CENTREL Solutions Ltd
Server audit and documentation tools.
http://www.centrel-solutions.com
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Setting properties to an empty value for the registry

Dear David,

The registry value has formatted type which means you can use [~] to set a null value instead. This is used by Windows Installer to author REG_MULTI_SZ character strings in the Registry table.

An alternative to using searches would be to place the registry value in a single key and use the registry key's preserve operation. You can try the following condition so that the key is preserved every-time the package is uninstalled:

Code: Select all

REMOVE="ALL"
... if you already released a version of your product, you can have the same preserve behavior by using OLDPRODUCTS in the condition instead. This property is set only in a package which upgrades another package.

Hope this helps,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
davidjhomer
Posts: 55
Joined: Wed Jun 08, 2016 3:58 pm
Contact: Website Facebook Skype Twitter

Re: Setting properties to an empty value for the registry

Hello,

Setting the Property to [~] sets the registry value to "[~]"

Setting the registry value directly to [~] changes it to a REG_MULTI_SZ

Ticking Preserve Key Content (with CONDITION set to 1) and setting the registry to a blank value does NOTHING - if you change the registry key value and perform an upgrade the value in the registry is set back to blank

I just want to set a property to a String.Empty blank value, I can't believe this is impossible with AdvancedInsataller without using VBscript!


Thanks,


Dave
CENTREL Solutions Ltd
Server audit and documentation tools.
http://www.centrel-solutions.com
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Setting properties to an empty value for the registry

Dear Dave,

To set the registry value blank by referencing a property you can initialize the property either to [~] or to {}. However, when referencing it be sure to do it like this:
reg value.png
reg value.png (11.96 KiB) Viewed 37056 times
...enclosing it in two sets of braces so that the resolved value is evaluated as formatted as well.

If you haven't released any versions of your product with the key you want preserved, you should set the condition to:

Code: Select all

REMOVE="ALL"
It tells the installer to preserve the key when the product is uninstalled (e.g. manually or by a higher version during upgrade).

Hope this helps,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
davidjhomer
Posts: 55
Joined: Wed Jun 08, 2016 3:58 pm
Contact: Website Facebook Skype Twitter

Re: Setting properties to an empty value for the registry

This does not work

If I use "-" or a space for the default property value it works with the registry setting and searches (but I have an annoying dash or space in the registry).

If I change the default property value to {} or [~] and change the registry value to [[SCHEDULER_CLIENTCERTIFICATETHUMBPRINT]] (with double brackets) every single upgrade then sets the registry value back to blank!


Dave
AATest.aip
(12.79 KiB) Downloaded 434 times
CENTREL Solutions Ltd
Server audit and documentation tools.
http://www.centrel-solutions.com
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Setting properties to an empty value for the registry

Dear Dave,

Keep in mind an upgrade consists of uninstall of the old version followed by install of the new version so both cases must be covered when conditioning the reg.

I attached my own consecutive version samples you can build. They are similar to your own and have the same settings except the version and Product Code:
Test Reg.zip
(6.18 KiB) Downloaded 329 times
Settings to consider are:
  • Condition for the "New Value" reg component in the Organization page:

    Code: Select all

    (NOT Installed) AND (NOT OLDPRODUCTS)
    => This is meant to install the reg (blank) only during a fresh installation but not during upgrade. It solves this:
    If I change the default property value to {} or [~] and change the registry value to [[SCHEDULER_CLIENTCERTIFICATETHUMBPRINT]] (with double brackets) every single upgrade then sets the registry value back to blank!
  • Removal operation set on parent key with condition:

    Code: Select all

    (REMOVE="ALL" AND (NOT UPGRADINGPRODUCTCODE))
    => This is meant to clean up the machine and remove the reg when the user manually uninstalls the product, but not when upgrading.
Hope this helps,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
davidjhomer
Posts: 55
Joined: Wed Jun 08, 2016 3:58 pm
Contact: Website Facebook Skype Twitter

Re: Setting properties to an empty value for the registry

Great thanks for the help, I didn't think to goto components (it's a bit confusing because there are conditions in the UI differently for each different item type)

Thanks,


Dave
CENTREL Solutions Ltd
Server audit and documentation tools.
http://www.centrel-solutions.com
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Setting properties to an empty value for the registry

You're welcome, a quick shortcut to open a file or registry's associated component in the Organization page is to press F8 while the resource is selected in the Files and Folders page or the Registry page.

Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
davidjhomer
Posts: 55
Joined: Wed Jun 08, 2016 3:58 pm
Contact: Website Facebook Skype Twitter

Re: Setting properties to an empty value for the registry

OK I've finished the review and that's a pretty messy solution.

I'm already taking into account the fact that there is an uninstall and install phase, that's why I'm using a Search so it should read the property from the registry, delete the registry value, and rewrite the registry key back to what it was.

This works correctly if I initialise the property to "00 00 00 00 00 00" or some other value but if I use your {} and [[PROPERTYNAME]] with the double brackets this does not work, it just overwrites the key each time ignoring the search - this is a bug in your product.

The problem with your solution here is that the order in which the removals works means that the parent registry keys aren't removed because they appear to have values in, this key delete option then runs and deletes the child keys by which time it's too late and the parent key isn't deleted. I'm not going to mark all keys manually for removal.

I would currently state that AdvancedInstaller does NOT support having properties that are initialised to blank, instead you must initialize your value to "[NOT SET]" or "000000000000" or something then recode your product to read these values as blank.


Dave
CENTREL Solutions Ltd
Server audit and documentation tools.
http://www.centrel-solutions.com
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Setting properties to an empty value for the registry

Dear Dave,
This works correctly if I initialise the property to "00 00 00 00 00 00" or some other value but if I use your {} and [[PROPERTYNAME]] with the double brackets this does not work, it just overwrites the key each time ignoring the search - this is a bug in your product.
This has to do with the way Windows Installer initializes public properties. Search names are interpreted as public properties as well and counting the one initialized in the Install Parameters page, I would say the engine gets confused which value to use for the reference in the Registry page.

Your approach seems simpler and cleaner. To fix the above issue:
- temporarily change the name of the search and of the property reference in the Registry
- delete the property from the Install Parameters page
- change the name of the search and of the property reference in the Registry back to CLIENT_CERT
- use single straight brackets when referencing it from the Registry page

Code: Select all

[CLIENT_CERT]
If the search is not successful it will set the property to a blank value anyway.
AATest.zip
(5.48 KiB) Downloaded 311 times
Regards,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”