我写的安装程序类

19 篇文章 0 订阅

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;

using Microsoft.Win32;
using System.Windows.Forms;

namespace MyInstall
{
    [RunInstaller(true)]
    public partial class Installer1 : Installer
    {
        string targetpath = null;
        public Installer1()
        {
            InitializeComponent();
        }

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            targetpath = this.Context.Parameters["targetpath"].ToString();
            string orahome = targetpath + "GVMS//ORACLE10";

           

 

            using (RegistryKey softkey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true))
            {
                RegistryKey gvmsKey = Registry.LocalMachine.OpenSubKey("SOFTWARE//GVMS1.0", true);
                if (gvmsKey == null)
                {
                    gvmsKey = softkey.CreateSubKey("GVMS1.0");
                    gvmsKey.SetValue("OraExist", "0");

                    gvmsKey.SetValue("Host", "");
                    gvmsKey.SetValue("Host Port", "");
                    gvmsKey.SetValue("Service Name","");

                    gvmsKey.SetValue("Data Source", "");
                    gvmsKey.SetValue("User ID", "");
                    gvmsKey.SetValue("Password", "");

                    gvmsKey.SetValue("SDE Server", "");
                    gvmsKey.SetValue("SDE Instance", "");
                    gvmsKey.SetValue("SDE User", "");
                    gvmsKey.SetValue("SDE Passwd", "");
                    gvmsKey.SetValue("SDE version", "");
                }

 

 

                using (RegistryKey orakey = softkey.OpenSubKey("ORACLE", true))
                {


                    if (orakey == null)
                    {
                        RegistryKey orakey1 = softkey.CreateSubKey("ORACLE");
                        RegistryKey homekey = orakey1.CreateSubKey("KEY_OraClient10g_home1");
                        homekey.SetValue("ORACLE_HOME", orahome);
                        homekey.Close();
                        RegistryKey pathkey = Registry.LocalMachine.OpenSubKey("SYSTEM//ControlSet001//Control//Session Manager//Environment", true);
                        string strpath = (string)pathkey.GetValue("path");
                        strpath += ";"+orahome + "//BIN;";
                        pathkey.SetValue("PATH", strpath);
                        pathkey.Close();


                    }
                    else
                    {
                        using (RegistryKey homekey = orakey.OpenSubKey("KEY_OraClient10g_home1", true))
                        {
                            if (homekey == null)
                            {
                                RegistryKey homekey1 = orakey.CreateSubKey("KEY_OraClient10g_home1");
                                homekey1.SetValue("ORACLE_HOME", orahome);

                                RegistryKey pathkey = Registry.LocalMachine.OpenSubKey("SYSTEM//ControlSet001//Control//Session Manager//Environment", true);
                                string strpath = (string)pathkey.GetValue("path");
                                strpath += ";" + orahome + "//BIN;";
                                pathkey.SetValue("PATH", strpath);
                                pathkey.Close();

                               
                            }//如果没有Oracle客户端,则要采用自带的。
                            else {
                                gvmsKey.SetValue("OraExist", "1");
                            }

                        }
                    }
                }
                gvmsKey.Close();
            }
        }


        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            base.Uninstall(savedState);
            //删除注册信息
            targetpath=this.Context.Parameters["targetpath"];
            RegistryKey softkey = Registry.LocalMachine.OpenSubKey("SOFTWARE", true);
            RegistryKey gvmsKey = softkey.OpenSubKey("GVMS1.0");
            string isExist =(string)gvmsKey.GetValue("OraExist");
            if (isExist == "0")//如果使用的是我的oracle,就要删除这个注册表
            {
                RegistryKey orhome=softkey.OpenSubKey("ORACLE//KEY_OraClient10g_home1",true);
                softkey.DeleteSubKeyTree("ORACLE");
                RegistryKey pathkey = Registry.LocalMachine.OpenSubKey("SYSTEM//ControlSet001//Control//Session Manager//Environment", true);
                string path = (string)pathkey.GetValue("Path");
                string delpath=(string)orhome.GetValue("ORACLE_HOME");
                delpath += "//BIN;";
                string newpath=path.Replace(delpath,"");
                pathkey.SetValue("Path",newpath);
            }
            softkey.DeleteSubKey("GVMS1.0");

               
        }

 

     
    }

 

 

注意如下:

1 在安装项目中添加 输出项 选择编写的安装程序

2 自定义操作 在安装 卸载 上右击 自定义操作

3 在添加的自定一操作的属性  CustomActionData后填写/targetpath="[TARGETDIR]/"

注意="[TARGETDIR]/"后面的那个斜杠.

如果是其他的,那么要不需要这个斜杠.比如说你添加的界面对话框,然后在Edit1Property后面写的那个值

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值