本文介绍了如何回滚我的安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#& amp;中开发了应用程序我创建了它的设置& amp;部署.我想在我的应用程序设置中添加序列号.当该串行密钥正确时,请安装我的应用程序,否则回滚我的应用程序.我一直在通过用户界面(添加对话框)添加文本框.
请检查以下代码

公共重写void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
试试
{
布尔值卸载= true;
字符串serialKey = Context.Parameters ["PathValue"];
如果(serialKey!="abcd")
{
卸载=假;
}
使用(var inst = new AssemblyInstaller(typeof(LicenseViewer.Program).Assembly,new string [] {}))
{
IDictionary状态= new Hashtable();
inst.UseNewContext = true;
试试
{
如果(卸载)
{
//inst.Uninstall(state);
inst.Rollback(state);
}
其他
{
inst.Install(状态);
inst.Commit(state);
}
}
赶上
{
试试
{
inst.Rollback(state);
}
catch(Exception e){MessageBox.Show(e.Message); }
投掷;
}
}

}
catch(ex ex例外)
{MessageBox.Show(ex.Message); }
}
当串行密钥在回滚之前的那个时间出错时,出现异常错误1001.找不到"namespace.installstate"".


我想检查文本框上的序列号(添加对话框).如果那次键不正确,那时候只显示消息无效键就不要转到下一页,如Microsoft Office安装程序.

I developed application in C# & I create its setup & deployment. I want to add serial key in setup of my application. When this serial key is right that time install my application otherwise rollback my application. I have been adding the textbox through User Interface (add dialog).
Please check the following code

public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
try
{
Boolean uninstall = true;
string serialKey = Context.Parameters["PathValue"];
if (serialKey!= "abcd")
{
uninstall = false;
}
using (var inst = new AssemblyInstaller(typeof(LicenseViewer.Program).Assembly, new string[] { }))
{
IDictionary state = new Hashtable();
inst.UseNewContext = true;
try
{
if (uninstall)
{
// inst.Uninstall(state);
inst.Rollback(state);
}
else
{
inst.Install(state);
inst.Commit(state);
}
}
catch
{
try
{
inst.Rollback(state);
}
catch (Exception e) { MessageBox.Show(e.Message); }
throw;
}
}

}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}
When the Serial key is wrong that time before rollback I got the exception "Error 1001. Could not find the ''namespace.installstate'' ".


I want to check serial key on textbox(add dialog).If key is wrong that time just show message invalid key not go to the next page like Microsoft Office setup.

推荐答案

if (uninstall)
  {
  //   inst.Uninstall(state);
  inst.Rollback(state);
}



因此,您会收到错误消息.



Thus you get an error.



这篇关于如何回滚我的安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:48