views:

129

answers:

2

Hi I have the following code from the ms site and I want to set the installation path from with in code (don't ask but trust me I need to!)

so how do I access and set the installation path from a custom action?

 public partial class Installer1 : System.Configuration.Install.Installer
    {
        public Installer1()
        {
            InitializeComponent();
            //need code to set the installation path

        }
        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            System.Diagnostics.Process.Start("http://www.microsoft.com");
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
    }
+1  A: 

You can't do that ... because the custom actions occur after the files have been installed from the MSI and set into the installation path. Otherwise, how could the custom actions be invoked? They are executed after they are available to the .NET installation APIs (which installUtil uses). So, you'd actually have to install to some path, then move them afterwards. Now, there's probably a way to do it via InstallShield or whatever installation toolset you may be able to get your hands on, to script it, but through .NET custom actions, you have certain limitations. (Another such limitation is modifying a configuration file based on input parameters from the installation wizard, before the installation has actually extracted the files to someplace.)

Richard Hein
A: 

You can do this,

If you want to access the installation path in your custom installer class, your first instinct is to use a [TARGETDIR] or [INSTALLDIR] as a custom action. Alas, this wont work, this will be populated after the custom action is executed So how ? string applicationInstalledPath = Context.Parameters["AssemblyPath"] will fetch the installed directory.

Prasenna