我想从另一个C#应用程序中按名称执行ClickOnce应用程序。 我当前的方法从Uninstall注册表项(HKCU \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall \ [PublicKeyToken] \ ShortcutAppId。)获取.Application文件的路径。
我们有一个网络文件夹,其中存储了我们的所有ClickOnce应用程序。 ClickOnce应用程序的每个快捷方式都以该文件夹中的.Application文件为目标。
将应用程序部署到Z:\ ClickOnceApps \ MyApp但是从\\ server \ share \ ClickOnceApps \ MyApp \ MyApp.application安装时出现问题。在这种情况下,存储在注册表中的ShortcutAppId是Z:\ ClickOnceApps \ MyApps \ MyApps.Application#[...]当我尝试使用此路径启动应用程序时,它会让我安装它,这让我觉得实际的安装路径是应用程序标识的一部分。
所以基本上我只能从安装它的同一路径启动一个应用程序。
我的问题:如何检索安装应用程序的精确路径(而不是部署路径)?
这是我为感兴趣的人检索ShortcutAppId的代码:
Public Class ClickOnceApp
Public Property DisplayName As String
Public Property UninstallString As String
Public Property PublicKeyToken As String
Public Property DisplayVersion As Version
Public Property ShortcutAppId As String
Public ReadOnly Property ShortcutPath As String
Get
Dim pawnIndex = ShortcutAppId.IndexOf("#"c)
If pawnIndex = -1 Then
Return ""
Else
Return ShortcutAppId.Substring(0, pawnIndex)
End If
End Get
End Property
Public Sub New(appUninstallKey As RegistryKey)
Me.DisplayName = appUninstallKey.GetValue("DisplayName")
Me.UninstallString = appUninstallKey.GetValue("UninstallString")
Me.PublicKeyToken = appUninstallKey.GetValue("PublicKeyToken")
Me.DisplayVersion = New Version(appUninstallKey.GetValue("DisplayVersion"))
Me.ShortcutAppId = appUninstallKey.GetValue("ShortcutAppId")
End Sub
Public Sub Launch()
Process.Start(ShortcutPath)
End Sub
End Class
Public Class ClickOnceHelper
Public Shared Function GetInstalledClickOnceApps() As ClickOnceApp()
Dim list As New List(Of ClickOnceApp)()
Using uninstallKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")
For Each subKeyName In (From keyName In uninstallKey.GetSubKeyNames() _
Where keyName.Length = 16)
Using appKey = uninstallKey.OpenSubKey(subKeyName)
If CStr(appKey.GetValue("UninstallString")).StartsWith("rundll32.exe dfshim.dll") Then
Dim app = New ClickOnceApp(appKey)
list.Add(app)
End If
End Using
Next
End Using
Return list.ToArray()
End Function
Public Shared Function FindClickOnceAppByName(name As String) As ClickOnceApp
Dim list = GetInstalledClickOnceApps()
Return (From app In list _
Where app.DisplayName.ToLower() = name.ToLower()).FirstOrDefault()
End Function
Public Shared Function FindClickOnceAppByPublicKey(publicKeyToken As String) As ClickOnceApp
Dim list = GetInstalledClickOnceApps()
Return (From app In list _
Where app.PublicKeyToken = publicKeyToken).FirstOrDefault()
End Function
End Class