【问题标题】:How can I retrieve the ClickOnce updater application, programatically?如何以编程方式检索 ClickOnce 更新应用程序?
【发布时间】:2012-09-08 14:59:57
【问题描述】:

我有一个 ClickOnce 应用程序,我想根据用户的选择在每次计算机启动时运行它。为此,我将应用程序的可执行文件添加到注册表。但这会直接启动应用程序,跳过 ClickOnce 搜索更新。 所以我需要 ClickOnce 应用程序的路径才能在注册表中正确设置。

【问题讨论】:

    标签: clickonce


    【解决方案1】:

    执行 .appref-ms 文件,开始菜单快捷方式(在安装 ClickOnce 时创建)执行。这就是我们在 VB.Net 中所做的:

    Dim FilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\Programs\[your publisher name]\[your app name]"
    Static p As Process
    
    Dim files As String()
    
    Try
        files = Directory.GetFiles(FilePath, "[your shortcut name]*.appref-ms")
    Catch ex As Exception
        '' an exception is thrown if no matching file exists
        '' you can open your ClickOnce URL in a webbrowser control here
        Return
    End Try
    
    If files.Length = 1 Then
        Dim psi As ProcessStartInfo = New ProcessStartInfo(files(0))
        psi.Arguments = "" 
        psi.WorkingDirectory = FilePath
        psi.UseShellExecute = True
        psi.CreateNoWindow = False
        psi.WindowStyle = ProcessWindowStyle.Normal
        psi.RedirectStandardOutput = False
        psi.RedirectStandardError = False
    
        Try
            p = Process.Start(psi)
            p.WaitForExit(50)
            p.Close()
        Catch ex As Exception
            ' handle error
        End Try
    Else
        ' more than one would be an anomaly
        If files.Length > 1 Then
            Dim f As String
            For Each f In files
                File.Delete(f)
            Next
        End If
    
        '' you can open your ClickOnce URL in a webbrowser control here
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多