我有一个ClickOnce应用程序,我想根据用户的选择每次启动计算机时运行它。为此,我将我的应用程序的可执行文件添加到注册表中。但这会直接启动应用程序,同时点击ClickOnce搜索更新。 所以我需要ClickOnce应用程序的路径才能在注册表中正确设置。
答案 0 :(得分: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