Click here to Skip to main content
15,887,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a C# solution with a setup project. When I install or install on a another computer, the installation path is not takeing. The setup install is always on C:\

eg: if the user selects c:\tools\MyProgam, the setup installs the package on c:\

For information, in my solution I have a custom action, and I change the defaultLocation.

C#
namespace GestionnaireTaches_Virtuel.Install
{
    [RunInstaller(true)]
    public  partial class GTVInstaller : Installer
    {
        #region Ctor(s)
        public GTVInstaller()
        {
            InitializeComponent();
        }
        #endregion Ctor(s)
        #region Public override Method
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            //Get the install folder and save it in the stateSaver
            string installFolder = Context.Parameters["TARGETDIR"];
            stateSaver.Add(INSTALLPATH, installFolder);
            //Unregister all DLL present
            UnRegisterDLL(installFolder, "TEST.DLL");
            //Register DLL
            RegisterDLL(installFolder, "TEST.DLL");
        }
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
        }
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
            string installFolder = savedState[INSTALLPATH].ToString();
            UnRegisterDLL(installFolder, "TEST.DLL");
        }
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
            string installFolder = savedState[INSTALLPATH].ToString();
            UnRegisterDLL(installFolder, "TEST.DLL");
        }
        #endregion Public override Method
        /// <summary>
        /// UnRegister the DLL define in parameter
        /// </summary>
        /// <param name="installFolder">Folder for acess to the dll</param>
        /// <param name="ddlName">Dll name (with extension)</param>
        private void UnRegisterDLL(string installFolder, string ddlName)
        {
            string argument = string.Format(@"/C regsvr32 /u /s {0}", Path.Combine(installFolder, ddlName));
            LaunchProcess("CMD.EXE", argument);
        }
        /// <summary>
        /// Register the DLL define in parameter
        /// </summary>
        /// <param name="installFolder">Folder for acess to the dll</param>
        /// <param name="ddlName">Dll name (with extension)</param>
        internal void RegisterDLL(string installFolder, string ddlName)
        {
            string argument = string.Format(@"/C regsvr32 /s {0}", Path.Combine(installFolder, ddlName));
            LaunchProcess("CMD.EXE", argument);
        }
        /// <summary>
        /// Launch a process on the computer(CMD.exe, explorer, ...)
        /// </summary>
        /// <param name="command">Nom de la commande</param>
        /// <param name="argument">Argument a passer à la commande</param>
        /// <param name="waitForExit">Définit si l'on doit attendre que la commande s'éxécute</param>
        private void LaunchProcess(string command,string argument, bool createWindow)
        {
            System.Diagnostics.ProcessStartInfo processStartInfo =
                                    new System.Diagnostics.ProcessStartInfo(command, argument);
            processStartInfo.CreateNoWindow = !createWindow;
            processStartInfo.UseShellExecute = createWindow;
            processStartInfo.RedirectStandardOutput = !createWindow;
            //Execute command with administrator account (UAC) for operation system great or equal to Vista
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                processStartInfo.Verb = "runas";
            }
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo = processStartInfo;
            process.Start();
            process.WaitForExit();
            process.Close();
        }
        private void LaunchProcess(string command, string argument)
        {
            LaunchProcess(command, argument, false);
        }

    }
}


Can you help me?

Thanks
Posted
Updated 14-Dec-10 1:35am
v3
Comments
senguptaamlan 14-Dec-10 6:15am    
please place the code of the custom action where you are changing the defaultLocation of the installation
Sebastien T. 14-Dec-10 7:36am    
I add the code of the custom action. For the defaultLocation is change in Application Folder properties

1 solution

try the following code
C#
public override void Install(IDictionary stateSaver)
        {
            //Get the install folder and save it in the stateSaver
            string installFolder = Context.Parameters["TARGETDIR"];
            stateSaver.Add(INSTALLPATH, installFolder);
            //Unregister all DLL present
            UnRegisterDLL(installFolder, "TEST.DLL");
            //Register DLL
            RegisterDLL(installFolder, "TEST.DLL");
           base.Install(stateSaver);
        }
 
Share this answer
 
v2
Comments
Toniyo Jackson 14-Dec-10 8:35am    
Removed extra space.
Sebastien T. 14-Dec-10 8:40am    
Thanks a lot of.
[no name] 14-Dec-10 9:11am    
ToniyoJackson: Edit was completely unnecessary. You are not an editor. Please refrain from future trivial editing exercises.
senguptaamlan 14-Dec-10 9:27am    
@Mark it's fine..at least the code was intact :)
fjdiewornncalwe 14-Dec-10 10:46am    
senguptaamlan: I don't think Toniyo has ever "broken" an answer with his edits, but his edits are typically trivial and nothing more than rep-point mining. Mark is just letting him know that the behavior has been noted and that it is not really considered acceptable behaviour. Cheers.

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