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后面写的那个值