2012-07-25 77 views
0

我有一個ClickOnce應用程序,我希望每次啓動計算機時都會根據用戶的選擇運行。爲此,我將我的應用程序的可執行文件添加到註冊表。但是,這直接啓動應用程序,滑動ClickOnce搜索更新。 所以我需要ClickOnce應用程序的路徑在註冊表中正確設置。如何以編程方式檢索ClickOnce更新程序?

回答

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