错误的安装路径 [英] Wrong install path

查看:104
本文介绍了错误的安装路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个带有安装项目的C#解决方案.当我在另一台计算机上安装或安装时,安装路径不可用.设置安装始终在C:\

例如:如果用户选择c:\tools\MyProgam,则安装程序将软件包安装在c:\

有关信息,在我的解决方案中,我有一个自定义操作,并且更改了defaultLocation.

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.

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

推荐答案

尝试以下代码
try the following code
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);
        }


这篇关于错误的安装路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆