0

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

4

1 回答 1

0

执行 .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
于 2012-09-08T06:59:57.570 回答