1新建类库项目2在新建的类库项目里添加安装程序类
3在安装程序类里面可以增加事件处理或重写某些函数,这些可在网上搜索。以下是安装程序类的一些代码可供参考:
using https://www.doczj.com/doc/387025852.html,ponentModel;
using
using System;
using
using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Reflection;
using
using System.Collections;
namespace SetupComponent
{
[RunInstaller(true)]
public partial class JSCADInstaller : Installer
{
public JSCADInstaller()
{
InitializeComponent();
}
//删除注册表
private void JSCADInstaller_AfterInstall(object sender, InstallEventArgs e)
{
}
//检查cad又没安装好
private void JSCADInstaller_BeforeInstall(object sender, InstallEventArgs e)
{
RegistryKey regAcadAppKey =
Registry.LocalMachine.OpenSubKey(@"Software\Autodesk\AutoCAD\R17.1\ACAD-6001:804", false);
if (regAcadAppKey == null)
{
MessageBox.Show("没有从注册表里找到AutoCAD安装成功记录!安装失败!");
Rollback(e.SavedState);
}
}
//将自己开发的程序加入注册表
private void JSCADInstaller_BeforeUninstall(object sender, InstallEventArgs e)
{
RegistryKey regAcadAppKey = Registry.LocalMachine.OpenSubKey("Software",
true).OpenSubKey("Autodesk", true).OpenSubKey("AutoCAD", true)
.OpenSubKey("R17.1", true).OpenSubKey("ACAD-6001:804", true).OpenSubKey("Applications", true);
string[] subKeys = regAcadAppKey.GetSubKeyNames();
foreach (string subKey in subKeys)
{
// If the application is already registered, delete
if (subKey.Equals("JSCAD1.0"))
{
regAcadAppKey.DeleteSubKey("JSCAD1.0");
}
}
regAcadAppKey.Close();
}
}
}
4新建安装程序项目
5在安装项目里,右击点击视图里的自定义操作,把你的包含有安装程序类的主输出添加进去。
这样注册功能就可以解决了!
其中,这里不光可以加入类库的主输出,也可以添加应用程序的主输出,这样你就可以先启动应用程序,再通过其它办法启动cad。当然这时你的程序已经在注册表里了。