2009-10-26 44 views
0

我有一个自定义安装程序类的安装项目,它在安装结束时启动应用程序。在设置中,我创建了应用程序输出的快捷方式。安装没问题。但是当我点击快捷方式时,安装程​​序将重新启动并且应用程序同时启动?为什么?C#安装项目中的快捷方式问题

不,我的自定义类的代码是:

/// <summary> 
/// Installer class to automatically launch the application at the end of the installation/ 
/// </summary> 
[RunInstaller(true)] 
public partial class InstallerStartApplication : Installer 
{ 
    /// <summary> 
    /// Initializes a new instance of the <see cref="InstallerStartApplication"/> class. 
    /// </summary> 
    public InstallerStartApplication() 
    {    
     InitializeComponent();    
    } 

    /// <summary> 
    /// Raises the <see cref="E:System.Configuration.Install.Installer.AfterInstall"/> event. 
    /// </summary> 
    /// <param name="savedState">An <see cref="T:System.Collections.IDictionary"/> that contains the state of the computer after all the installers contained in the <see cref="P:System.Configuration.Install.Installer.Installers"/> property have completed their installations.</param> 
    protected override void OnAfterInstall(IDictionary savedState) 
    { 
     base.OnAfterInstall(savedState); 


    } 

    // Override the 'Install' method. 
    public override void Install(IDictionary savedState) 
    { 
     base.Install(savedState); 
    } 

    // Override the 'Commit' method. 
    public override void Commit(IDictionary savedState) 
    {   
     base.Commit(savedState); 

     try 
     { 
      Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); 
      Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "IERssNotificator.exe"), "-c"); 
     } 
     catch (Exception ex) 
     { 
      Debug.WriteLine(ex); 
     } 
    } 

    // Override the 'Rollback' method. 
    public override void Rollback(IDictionary savedState) 
    { 
     base.Rollback(savedState); 
    } 


} 

我推出这个在安装和提交自定义操作。

回答

1

好的,我发现了这个问题。该错误是在自定义安装程序类的代码:

Process.Start(Path.Combine(Directory.GetCurrentDirectory(), "IERssNotificator.exe"), "-c"); 

此次发布的一个过程,而不是异步设置永远不会结束。这就是为什么它总是重新启动设置。

我将我的代码和laucn进程更改为单独的线程,因此安装完成。

1

安装项目放置特殊类型的快捷方式。它不会简单地启动你的程序。它首先检查随程序一起安装的所有文件。如果他们这样做,它会启动程序,如果他们不安装程序再次从msi缓存运行重新安装缺少的文件。

您是否有安装后操作来删除一些已安装的文件?

+0

不,请参阅我的代码...以上 – Coolweb

+0

有什么办法让它创建一个* normal *快捷键而不是触发安装程序的排序? –

+0

我没有找到它。最后,我使用WinAPI在Commit操作中创建了快捷方式。您可以使用WScript.Shell或http://www.msjogren.net/dotnet/eng/samples/dotnet_shelllink.asp库 –

相关问题