你用的是VS自带的安装还是自己写的?
可以自己写一个winform的安装程序 读注册表

解决方案 »

  1.   

    添加一个安装部署工程,右键添加一个安装类
    重写安装类相应的方法,比如安装前BeforeInstall方法读取注册表即可
    http://www.cnblogs.com/yuanwoneng/archive/2009/07/10/1520291.html
      

  2.   

    要么你就自己写打包程序,要么就好好研究VS自带的打包程序应该如何设置,要么用第三方的打包程序
    用VS自带的打包程序,安装的时候,你的程序根本还没有运行,研究个什么劲,有什么用
      

  3.   

    要么你就自己写打包程序,要么就好好研究VS自带的打包程序应该如何设置,要么用第三方的打包程序
    用VS自带的打包程序,安装的时候,你的程序根本还没有运行,研究个什么劲,有什么用我的程序已经运行了,我现在每次覆盖安装还是需要重新选择安装路径
      

  4.   

    你的程序运行,是运行的程序A
    而你要安装的,是程序B
    虽然他俩是同一个程序的升级版本,但是你不在打包的时候配置好,电脑可不知道他俩是一个东西你安装程序B的时候,程序A运行有什么用啊,程序A去修改程序B的安装路径?
    你覆盖安装的时候,不先退出A,能覆盖?
    而程序B,还在压缩包里呢,它能自己运行?
    运行的不过是打包程序而已
      

  5.   


    对,我就是要在打包的时候配置,我在网上查资料this.Context.Parameters["targetdir"]这个是可以实现的,但是我这句代码是加到哪里,我打包程序的自定义操作里也添加了/targetdir="[TARGETDIR]\"
      

  6.   

    所以说,你把打包安装过程,和程序运行过程,搞混了啊
    虽然我也不知道VS的打包怎么配置(我都是用第三方打包,不用VS自带的打包)
    但是我知道,你的这个this.Context.Parameters["targetdir"]代码,只有程序运行时才好用,跟安装过程一点关系都没有
      

  7.   

    已经写入注册表,知道具体注册表的位置就好了
    regSubKey.GetValue("path").ToString();
      

  8.   

    建议了解一下安装类的使用,按照下文的方法添加安装类(继承自System.Configuration.Install.Installer)
    前面那些添加自定义步骤可以跳过,直接看添加安装类,然后重写
    http://www.cnblogs.com/sunrack/articles/944153.html
    http://msdn.microsoft.com/zh-cn/library/system.configuration.install.installer.aspx利用BeforeInstall事件或重写方法,读取注册表值并设置targetDir参数
      

  9.   


    private void InstallerTest_BeforeInstall(object sender, InstallEventArgs e)
            {
                string strPathResult = string.Empty;
                string strKeyName = "";
                object objResult = null;            Microsoft.Win32.RegistryValueKind regValueKind;
                Microsoft.Win32.RegistryKey regKey = null;
                Microsoft.Win32.RegistryKey regSubKey = null;
                string softName = "Stephen";
                try
                {
                    //Read the key
                    regKey = Microsoft.Win32.Registry.LocalMachine;
                    regSubKey = regKey.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" + softName.ToString() + ".exe", false);                //Read the path
                    objResult = regSubKey.GetValue("Path").ToString();
                    regValueKind = regSubKey.GetValueKind(strKeyName);                //Set the path
                    if (regValueKind == Microsoft.Win32.RegistryValueKind.String)
                    {
                        strPathResult = objResult.ToString();
                       // this.Context.Parameters["targetdir"] = strPathResult;
                    }
                }
                catch (System.Security.SecurityException ex)
                {
                    throw new System.Security.SecurityException("You have no right to read the registry!", ex);
                }
                catch (Exception ex)
                {
                    throw new Exception("Reading registry error!", ex);
                }
                finally
                {                if (regKey != null)
                    {
                        regKey.Close();
                        regKey = null;
                    }                if (regSubKey != null)
                    {
                        regSubKey.Close();
                        regSubKey = null;
                    }
                }
            }
    我已经把读取注册表写到这个事件里了,但是还是不管用呢,customactiondate属性我也设置成/targetdir="[TARGETDIR]\"