thebouncer2006
Posts: 2
Joined: Tue Jan 08, 2008 7:17 pm

Return orginal registry value if MSI is uninstalled

Hello,

I am trying to do the following

Make an msi that can presents the user with a screen that the user can select the individual items to install

These items are registry changes

The registry changes are located in

HKLM\SYSTEM\CurrentControlSet\Services

Under subkeys such as

Alerter
Browser

and so forth these are the Windows XP services. What I would like to do is make an msi that can change the DWORD "Start" value to "4" from whatever it's current setting is thereby disabling the windows service.

So far I have gotten this to work but here is where the problem if the package is selected for removal in add/remove programs it is COMPLETELY removing the DWORD "Start" instead of putting it back to it's original value.

How can I make it so that if originally the DWORD "Start" Value was "1" I thhen write the MSI to change it to "4" but then uninstall it, it then returns back to the value "1" instead of the MSI removing the entire thing.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

This can be done by using custom actions which backup and restore the registry entry. There is a how-to for performing backup and restore to a file:
http://www.advancedinstaller.com/user-g ... le-ca.html

You can modify the script in order to perform the registry entry backup and restore.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
thebouncer2006
Posts: 2
Joined: Tue Jan 08, 2008 7:17 pm

I do not know how to script.

I also do not see any mention of registry in the example file..

I do not understand how I would modify it could you show me an example of how it would be modified ?
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Hi,

For this example we will consider the "Test Key" registry key which contains the string value "Test". Also, in the "Registry" page of your Advanced Installer project you must add the new value of the "Test" entry (create the "Test Key" and "Test" entries under HKEY_LOCAL_MACHINE\Software).

Here is an example for the backup custom action:

Code: Select all

Function backup

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Test Key"
strValueName = "Test"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\Test Key backup"
oReg.CreateKey HKEY_LOCAL_MACHINE,strKeyPath

strValueName = "Test backup"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

End Function 
This custom action can be scheduled under the "RegisterMIMEInfo" standard action (right before the registry entries are created).

The restore custom action looks like this:

Code: Select all

Function restore

const HKEY_CURRENT_USER = &H80000001
const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
 strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Test Key backup"
strValueName = "Test backup"
oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\Test Key"
strValueName = "Test"
oReg.SetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue

strKeyPath = "SOFTWARE\Test Key backup" 
oReg.DeleteKey HKEY_LOCAL_MACHINE, strKeyPath

End Function 
This custom action can be scheduled under the "Commit" standard action. Note that for this custom action you must use the condition REMOVE = "ALL" in order to make sure that it is executed only during the uninstall.

Also, you need to make sure that the registry entry is not removed at uninstall (it is replaced by the old value). For this you go to the "Organization" page and set the "Permanent" attribute for the component of the "Test" registry value.

Note that if you use DWORD values then you replace strValue with dwValue in the scripts.

You can modify these scripts for the registry entry you need.

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”