Click here to Skip to main content
14,766,280 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
We have installed our application using the installer package (msi) in Visual Studio 2010 on one of our terminal servers and had an issue with Oracle.

As it turned out the error we were getting was due to this key in the registry:

If the HKEY_LOCAL_MACHINE\Software\Oracle\NLS_LANG registry entry is set to "NA" ORA-12705 errors will be encountered when using ODP.NET.

We have been researching a way to delete the key upon installation of the package and have come accross a lot of information that does not really apply specifically to deleting registry keys from an msi installation.

How could we go about deleting a registry key during msi installation from Visual Studio 2010?
Posted

If you are using an msi, just add a Custom Action to the msi.
   
Comments
Zamshed Farhan 4-Feb-13 0:16am
   
Not clear to me as I am a newbie. Is it right way to write registry entry on development time, then make msi from the development?
Hi,

You can do this using an installer class.

public partial class Installer1 : Installer

....

public override void Commit(IDictionary savedState)
{
    Registry.LocalMachine.DeleteSubKey(@"HKEY_LOCAL_MACHINE\Software\Oracle\NLS_LANG");
    base.Commit(savedState);
}


You then need to use your installer class in the setup project.
In Solution Explorer, select the "Custom action" icon (the one with a cog) and add the primary output of your installer class to the commit node.

Valery.

http://msdn.microsoft.com/en-us/library/d9k65z2d(v=VS.100).aspx[^]
   
Comments
hrdfsique 27-May-11 14:33pm
   
Thanks Valery...

Your's, so far, is the closest to being an actual solution.

I have already tried something like this (I will include code) but I can not get past security. You will see in my code where I attempted to give the user complete control over that specific key... but still no go.

I am contemplating using a batch (reg) file and calling the file in command line during install but that still leads to security issues.

I have been testing this as a user with Administrator profile (this will be done as install over RDC on Terminal Servers) but it still gives me authorization issues.

<pre>using System;
using System.Diagnostics;
using System.ComponentModel;
using System.Configuration.Install;
using System.Text;
using Microsoft.Win32;
using System.Security;
using System.Security.AccessControl;

namespace MyAppInstaller
{
[RunInstaller(true)]
class MyAppInstaller : Installer
{
static void Main(string[] args)
{
string user = Environment.UserDomainName + "\\" + Environment.UserName;

RegistrySecurity rs = new RegistrySecurity();

// Allow the current user to read and delete the key.
//
rs.AddAccessRule(new RegistryAccessRule(user,
RegistryRights.ReadKey | RegistryRights.Delete | RegistryRights.WriteKey,
InheritanceFlags.None,
PropagationFlags.None,
AccessControlType.Allow));

string keyName = @"SOFTWARE";
string subKey = @"Brett";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName, true))
{
key.SetAccessControl(rs);
string[] arrayKeys = key.GetSubKeyNames();
if (key != null)
{
key.DeleteSubKeyTree(subKey);
}
}
}
}
}</pre>
Never really tried doing this with msi, but if you need to do it programatically, you just need to read up on RegDeleteValue(), very easy to use (for C/C++). You can always run a small executable that at the beginning of the msi to check if the registry key exists and delete it if it does. But most install builders should be able to handle this anyway.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900