2010-10-13 131 views
11

即時通訊部署應用程序,並在安裝過程中,在用戶選擇安裝應用程序的位置後,我想要獲取該路徑,im已經在自定義操作中,但我不知道如何獲取應用程序路徑它將被安裝!在安裝過程中獲取應用程序的路徑

其Windows窗體和即時通訊開發使用Visual Studio 2010「C#」。

和即時使用默認的部署工具...

任何想法?

在此先感謝...

+0

基於「自定義操作」,我猜你正在使用Windows Installer。您是使用Wix還是Visual Studio安裝項目? – 2010-10-13 15:19:44

+0

oh im對不起,我忘了提供更多的信息,我將編輯我的問題... – Stacker 2010-10-13 15:20:20

回答

32

類自定義操作是應該System.Configuration.Installer.Installer繼承。它有一個名爲Context的參數,它有一個參數字典。該字典包含大量有關安裝的有用變量,您可以添加一些。

將自定義安裝程序添加到自定義操作窗格中的安裝項目後。選擇安裝動作和CustomActionData屬性設置爲:

/targetdir="[TARGETDIR]\" 

然後你就可以訪問這樣的路徑:

[RunInstaller(true)] 
public partial class CustomInstaller : System.Configuration.Install.Installer 
{ 
    public override void Install(System.Collections.IDictionary stateSaver) 
    { 
     base.Install(stateSaver); 
     string path = this.Context.Parameters["targetdir"]; 
     // Do something with path. 
    } 
} 
+1

這不工作:( – Stacker 2010-10-13 16:21:57

+0

我的不好。你還需要設置CustomActionData屬性。更新發布。 – 2010-10-13 17:28:26

+0

如何在visual C++中使用TARGETDIR? – karikari 2011-02-22 06:19:35

1

我知道這是VB,但是這爲我工作。

Private Sub DBInstaller_AfterInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.AfterInstall 

    MessageBox.Show(Context.Parameters("assemblypath")) 

End Sub 
+0

似乎它不回答這個問題。 – 2014-03-11 20:20:21

0

很抱歉張貼老帖子的答案,但我的答案可能有助於其他。

public override void Install(System.Collections.IDictionary stateSaver) 
{ 
    base.Install(stateSaver); 
    rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 
    if (rkApp.GetValue("MyApp") == null) 
    { 
     rkApp.SetValue("MyApp", this.Context.Parameters["assemblypath"]); 
    } 
    else 
    { 
     if (rkApp.GetValue("MyApp").ToString() != this.Context.Parameters["assemblypath"]) 
     { 
      rkApp.SetValue("MyApp", this.Context.Parameters["assemblypath"]); 
     } 
    } 
} 

public override void Uninstall(System.Collections.IDictionary savedState) 
{ 
    base.Uninstall(savedState); 
    rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); 

    if (rkApp.GetValue("MyApp") != null) 
    { 
     rkApp.DeleteValue("MyApp", false); 
    } 
} 
相關問題