Create custom Registry Values - Advanced Installer Community
blessy
Posts: 10
Joined: Thu Sep 07, 2017 8:06 am

Create custom Registry Values

I have already existing registry values and key. I want to add a new key and value but I need to count number of keys present in the registry 1st and replace the value of one key and add a new key value pair to this registry entry.
For example the structure will be:

Software
|_DATA(Folder)
|_ NumOfVal(key) 2(value)
|_ Entry1(key) f:/abc.txt(value)
|_ Entry2(key) d:/bc.txt(value)

I want to get the NumOfVal's value and replace it by value+1 and add my new entry. How to acheive this scenario?
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Create custom Registry Values

Hello,
I want to get the NumOfVal's value and replace it by value+1 and add my new entry. How to acheive this scenario?
To achieve this you have to first retrieve the value from the registry.

This could be done using a Search operation. Just go to "Search" page, create and create a new search. Right click on it and choose "Add Location -> Registry". Configure the Key name - for example "SOFTWARE\DATA", the value name - for example "NumOfVal".
This search operation will retrieve the content of the specified registry value in a property - RESULT_PROPERTY. Please note that the Windows Installer search operations always return a string. Windows installer stores the registry values using a prefix (one or more characters) to differentiate between the registry types (for example between DWORD and STRING). For DWORD values this prefix is "#" so the RESULT_PROPERTY property value will be a string like "#3" if the searched DWORD registry value is 3.
You could find more details here : Registry Table

First you have to parse the string in order to remove the prefix character. Then, you have to convert this string to an integer and increment it. All these action could be done using a VBS script custom action. Go to "Custom Actions" page and create a new "Execute Inline Script Code" custom action with sequence and place it after "Searches" in "Install Execution Stage" Use thw following VBS code:

Code: Select all

mystring = Session.Property("RESULT_PROPERTY")
mystring = Right(mystring,Len(mystring) - 1)
Session.Property("RESULT_PROPERTY") = mystring
Session.Property("RESULT_PROPERTY") = CStr(CInt(session.property("RESULT_PROPERTY")) + 1)
This custom action should only run on "Install"

In the end, you have to go to "Registry" page and create a new registry value in which you need to store the incremeted value. You should also choose "Replace existing value" option as you need to update an existing value. In the "Data" field you should enter the formatted reference to the RESULT_PROPERTY property - "[RESULT_PROPERTY]"

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blessy
Posts: 10
Joined: Thu Sep 07, 2017 8:06 am

Re: Create custom Registry Values

Thanks for the reply.. :)
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Create custom Registry Values

Hello,

You are welcome.

Please let me know if you have any other questions.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blessy
Posts: 10
Joined: Thu Sep 07, 2017 8:06 am

Re: Create custom Registry Values

I am finding an issue of after uninstall the numVal gets deleted. how can i resolve this? I want to retain the present value of numVal-1. I did it in execute-inline script still its deleting numval and string is not getting deleted.
1 more question can we create if the search registry is not there in registry?
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Create custom Registry Values

Hello,
I am finding an issue of after uninstall the numVal gets deleted. how can i resolve this?
You can achieve this by going to "Registry" page, selecting the numVal value and press F8 (go to component). Then you should enable the "Permanent" option for this component. In this way the registry value will not be removed at uninstall.
I want to retain the present value of numVal-1. I did it in execute-inline script still its deleting numval and string is not getting deleted.
To implement this requirement you have to create a new Execute Inline Script custom action configured to run only on Uninstall. This script should be configured to decrement the value if is is larger than 1 and to delete the registry value if its value is 1.
1 more question can we create if the search registry is not there in registry?
To achieve this you can modify the solution I've presented as follows:

-go to "Registry page" and double click on the value. In the "Data" field enter "[RESULT_PROPERTY_NEW]" instead of "[RESULT_PROPERTY]"
-go to "Install Parameters" page and add a new property in the "Properties" field. In the "Name" field enter RESULT_PROPERTY_NEW and in the "Value" enter "1"
-go to "Search" page and rename the result property of your search to "RESULT_PROPERTY_NEW"
-go to "Custom actions" page and select the Execute Inline Script custom action. Modify the script by replacing RESULT_PROPERTY with RESULT_PROPERTY_NEW
-condition this custom action with the following condition : RESULT_PROPERTY1 <> "1"

In this way, if the registry value doesn't exist, it will be created with the default value "1"

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blessy
Posts: 10
Joined: Thu Sep 07, 2017 8:06 am

Re: Create custom Registry Values

Is it RESULT_PROPERTY_NEW we have to condition?

Code: Select all

if RESULT_PROPERTY_NEW<>1 then
   mystring = Session.Property("RESULT_PROPERTY_NEW")
   mystring = Right(mystring,Len(mystring) - 1)
   Session.Property("RESULT_PROPERTY_NEW") = mystring
   Session.Property("RESULT_PROPERTY_NEW") = CStr(CInt(session.property("RESULT_PROPERTY_NEW")) + 1)
end if
How can i get the help file for vbscript which is used in custom action?
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Create custom Registry Values

Hello,
Is it RESULT_PROPERTY_NEW we have to condition?
Yes, you need to condition the custom action by RESULT_PROPERTY_NEW. I've made a small typo in my previous post:
-condition this custom action with the following condition : RESULT_PROPERTY1 <> "1"
should be
-condition this custom action with the following condition : RESULT_PROPERTY_NEW <> "1"
I would recommend conditioning the custom action itself from "Execution Stage Condition" field.
How can i get the help file for vbscript which is used in custom action?
Usually our time resources are limited and we cannot help our customers with development code for their custom actions, but in your case I can help you with a small VBS. Here is an example vbscript code for your scenario :

Code: Select all

mystring = Session.Property("CustomActionData")
mystring = Right(mystring,Len(mystring) - 1)
if mystring > "1" then
mystring = CStr(CInt(mystring) - 1)
Set WshShell = CreateObject("WScript.Shell")
myKey = "HKEY_LOCAL_MACHINE\Software\YourKey\Value"
WshShell.RegWrite myKey,mystring,"REG_DWORD"
elseif mystring = "1" then
Set objRegistry = CreateObject("Wscript.Shell")
objRegistry.RegDelete "HKEY_LOCAL_MACHINE\Software\YourKey\Value"
end if
- You need to insert this code in a "Execute Inline Script Code" custom action, placed after your first vbsript custion action.
- This new custom action should run "When the system is being modified (deferred) and with "Run under the LocalSystem account with full privileges(no impersonation)".
- This custom action must be configured to run only on "Uninstall" from "Execution Stage condition" field.
- If the registry value is under the 64-bit part of the registry, the "64-bit script" option must be enabled.
- In order to be able to access properties from a deferred custom action you need to enter the formatted reference [RESULT_PROPERTY_NEW] in the Action data field of the custom action.

This script will be executed on uninstall and will decrement the value from the registry if it is larger than 1 and it will delete the registry key if the value is 1.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
blessy
Posts: 10
Joined: Thu Sep 07, 2017 8:06 am

Re: Create custom Registry Values

Hello,

I have 2 scenario's:
Install and Uninstall

For Install:

While installing program should be installed such a way that registry value should be added if its not present else increment the registry value. (Problem I am facing is I can add to registry only if the value is there in registry since you had told me to add search registry value in search page. How to overcome this)
- This new custom action should run "When the system is being modified (deferred) and with "Run under the LocalSystem account with full privileges(no impersonation)".
If we are placing the execute inline after search these options are disabled. Registry value which I have is in CurrentUser(HKEY_CURRENT_USER)

So I am getting confused where to place the code and how to do the operations.

About Registry permission I have all permission on registry when I am doing using REGEDIT. But while using through advanced installer I am getting only read right. Please help me ASAP. Kindly please tell me Is there any means through which I can contact you directly through call or skype as it is bit urgent.
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Create custom Registry Values

Hello,

I'm afraid we cannot provide live technical support because of our work load and limited resources. Mainly this is because we have a lot of support tickets and each requires careful investigation. Thank you for your understanding.

Regarding your scenario, I've attached a sample .AIP project configred to your requirements. This project will generate a setup with the following behavior at install time:

- it will create a DWORD registry value if it is not present on the machine. It's value will be "1"
- it will increment a DWORD registry value if it is present on the target machine

Un uninstall the behaviour will be:
- it will decrement a DWORD registry value if this value is larger than "1"
- it will delete the registry value value if this value is "1"

Just let me know if you have any other questions.

Best regards,
Sorin
Attachments
sample project.zip
(3.6 KiB) Downloaded 412 times
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”