Ahmed の回答のフォローアップとして、以下は VB.NET のコードにマイナーな機能強化を加えたものです。ベスト プラクティスに従っていない可能性がありますが、読みやすく説明的です。
''' <summary>
''' Checks if the update is available for network based deployment and download it.
''' </summary>
''' <param name="autoDownloadUpdate">If the update is available, should it be downloaded automatically.<para>Default value is <code>True</code></para></param>
''' <returns>It will return <code>True</code> only if the latest version is already installed.
''' <para>If autoDownloadUpdate is set to <code>True</code>, the update is auto downloaded (and app restarts and nothing is returned) else it returns <code>False</code>.</para>
''' </returns>
Shared Private Function CheckAndDownloadUpdate(ByVal Optional autoDownloadUpdate As Boolean = True) As Boolean
If ApplicationDeployment.IsNetworkDeployed = False Then Return False
Dim appDeployment As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Dim info As UpdateCheckInfo = Nothing
Try
info = appDeployment.CheckForDetailedUpdate
Catch ex As Exception
' Exceptions if you want to handle individually
'DeploymentDownloadException ' No network connection
'InvalidDeploymentException
'InvalidOperationException
Return False
End Try
' If no update is available, it means latest version is installated
If info.UpdateAvailable = False Then Return True
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' If we are here, it means an update is available on the network
' if autoDownload is False, simply return False
If autoDownloadUpdate = False Then Return False
Try
appDeployment.Update()
Application.Restart()
Environment.Exit(0)
Catch ex As DeploymentDownloadException
' No network connection
Return False
End Try
End Function
その後、スタートアップ コードで、次のように呼び出すことができます
CheckAndDownloadUpdate()
回答をさらに強化するためのフィードバック...