您的位置:程序门 -> .net技术 -> c#



用dotnet做安装项目,如何在安装过程中取消安装!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


用dotnet做安装项目,如何在安装过程中取消安装!
发表于:2007-03-08 10:37:13 楼主
在用dotnet做安装项目的时候,我在install(system.collections.idictionary   statesaver)方法中想取消安装,请问怎么做啊?
发表于:2007-03-08 12:25:121楼 得分:0
up
发表于:2007-03-09 16:20:562楼 得分:0
大家帮我看看!!!
发表于:2007-03-09 16:35:403楼 得分:0
重写install()方法啊
发表于:2007-03-09 16:40:314楼 得分:0
哥们!!能不能具体些?
发表于:2007-03-09 16:51:015楼 得分:0
不需要重新写,本来就有这个功能.
发表于:2007-03-09 16:52:506楼 得分:0
当然是点 "取消 "按钮
发表于:2007-03-09 16:58:007楼 得分:0
帮你顶
发表于:2007-03-09 17:00:078楼 得分:0
找安装工具,比如:easyinstall   之类的,它会帮你处理的。
发表于:2007-03-09 22:28:489楼 得分:0
不知道   楼主   具体   要做什么?
.net制作的   安装包   本来就有   取消   回滚啊
发表于:2007-03-11 10:44:0610楼 得分:0
using   system;
using   system.io;
using   system.xml;
using   system.collections;
using   system.diagnostics;
using   system.componentmodel;
using   system.configuration.install;

namespace   petshopsetlib
{

[runinstaller(true)]
public   class   petshopinstaller   :   system.configuration.install.installer
{

private   system.componentmodel.container   components   =   null;

public   petshopinstaller()
{
initializecomponent();
}

protected   override   void   dispose(   bool   disposing   )
{
if(   disposing   )
{
if(components   !=   null)
{
components.dispose();
}
}
base.dispose(   disposing   );
}

public   override   void   install(idictionary   statesaver)
{
base.install   (statesaver);

//   osql   -u   sa   -p   sa   -q "sp_attach_db   'petshop ',   'e:\petshop\petshop.mdf '   , 'e:\petshop\petshop_log.ldf '
string   format   =   string.format( "-u   sa   -p   sa   -q\ "sp_attach_db   \ 'petshop\ ',\ '{0}\\petshop.mdf\ ',\ '{1}\\petshop_log.ldf\ ' ",
this.context.parameters[ "targetdir "],this.context.parameters[ "targetdir "]);
EXECuteosql(format);
}

public   override   void   uninstall(idictionary   savedstate)
{
try
{
//   osql   -u   sa   -p   sa   -q "sp_detach_db   'petshop '
string   format   =   "-u   sa   -p   sa   -q\ "sp_detach_db   \ 'petshop\ ' ";
EXECuteosql(format);
}
catch(exception   ex){console.writeline(ex.message);}
base.uninstall   (savedstate);
}

//   执行安装和卸载数据库
private   void   EXECuteosql(string   format)
{
process   sqlprocess   =   new   process();
sqlprocess.startinfo.filename   =   "osql.exe ";
sqlprocess.startinfo.arguments   =   format;
sqlprocess.startinfo.windowstyle   =   processwindowstyle.hidden;
sqlprocess.start();
sqlprocess.waitforexit();
sqlprocess.close();
}

//   更改配置文件
private   void   changewebconfig(string   pwd)
{
bool   isfound   =   false;
try
{
fileinfo   fileinfo   =   new   fileinfo(this.context.parameters[ "targetdir "]   +   "\\web.config ");

if   (!   fileinfo.exists)
throw   new   installexception( "没有找到配置文件 ");

//   实例化文档
xmldocument   xmldoc   =   new   xmldocument();
xmldoc.load(fileinfo.fullname);

//   查找appsettings中的节点
foreach   (xmlnode   node   in   xmldoc[ "configuration "][ "appsettings "])
{
if   ((node.name   ==   "add ")   &&   (node.attributes.getnameditem( "key ").value   ==   "connectionstring "))
{
//   写入连接字符串
node.attributes.getnameditem( "value ").value   =   null;   //string.format();

isfound   =   true;
break;
}
}
                               
if   (!isfound)
throw   new   installexception( "web.config   文件没有包含connectionstring连接字符串设置 ");

xmldoc.save(fileinfo.fullname);
}
catch(exception   ex)
{
throw   ex;
}
}

#region   组件设计器生成的代码
///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   initializecomponent()
{
components   =   new   system.componentmodel.container();
}
#endregion
}
}


快速检索

最新资讯
热门点击