0
我有一个ClickOnce应用程序,我希望每次启动计算机时都会根据用户的选择运行。为此,我将我的应用程序的可执行文件添加到注册表。但是,这直接启动应用程序,滑动ClickOnce搜索更新。 所以我需要ClickOnce应用程序的路径在注册表中正确设置。如何以编程方式检索ClickOnce更新程序?
我有一个ClickOnce应用程序,我希望每次启动计算机时都会根据用户的选择运行。为此,我将我的应用程序的可执行文件添加到注册表。但是,这直接启动应用程序,滑动ClickOnce搜索更新。 所以我需要ClickOnce应用程序的路径在注册表中正确设置。如何以编程方式检索ClickOnce更新程序?
执行.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