oz1cz
Posts: 17
Joined: Thu Oct 01, 2009 10:49 am

Increment / decrement registry value

I would like to do the following:

When my product is being installed:
Check if a certain registry key exists. If it doesn't, create it with a numeric value of 1; if it does exist, increment its value.

When my product is being uninstalled:
Decrement the registry key value. If it reaches 0, execute a specific program.

Is this possible?

--
Claus
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Increment / decrement registry value

Hello,

This is not directly supported by Advanced Installer. You can however use a Search to retrieve your property from the registry, increment it using a vbscript "Launch File or Open URL" custom action, then write it back in the registry using the Registry Page.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
shelmers
Posts: 63
Joined: Thu Sep 03, 2009 9:02 pm
Location: Andover, Massachusetts USA

Re: Increment / decrement registry value

Claus,

You can increment a registry value without an external script -- I modified Gabriel's idea slightly as you'll see...

Create a search NBR_INSTALLS that obtains the current registry value. Create a "VBScript inline" custom action with this line of code (the conversions to integer and string values are necessary to 1) do the math, and 2) write back to the property):

Code: Select all

session.property("NBR_INSTALLS") = CStr(CInt(session.property("NBR_INSTALLS")) + 1)
Finally, use the registry page to write NBR_INSTALLS back to the registry.

There are a few things to watch out for with this scheme, like the very first install when the reg key doesn't exist, but I added another one-line script to solve that problem (see attached project, which also contains three debug message scripts you can delete).

The logic for decrementing the reg value would be similar. I haven't thought through what happens when the count gets to 0, but I'm not sure you'd need to do anything special. You could just leave the reg key behind on the user's system. That may not be the best policy but it isn't a terrible thing either.

Scott
Attachments
Increment Reg Count.aip
sample project to increment registry value
(9.15 KiB) Downloaded 472 times
oz1cz
Posts: 17
Joined: Thu Oct 01, 2009 10:49 am

Re: Increment / decrement registry value

Thank you, Scott, that is very informative.

--
Claus

Return to “Common Problems”