I have written a custom update program to automatically update my Tray Menu application from a network resource. However, if when this application runs (at login) the network share is not available, the program throws an ugly error instead of just gracefully exiting and launching the Tray Menu app that is already installed on the user's machine. If the network share is available it runs perfectly fine and updates the Tray menu application as needed.
I have included the code (below). I have coloured the line in red that I think is causing the error and as this happens before I can insert an error trap to deal with the absence of the network share, I can't see how to stop the problem. Is there a simple solution that will prevent the error? Any help will be greatly appreciated as this one is stumping me.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim web As New WebClient 'To be able to download the content from the latest version file you have stored.
Dim versionInfo As FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo("C:\Apps\1DTools\1DTrayMenu.exe")
Dim LatestVersion As String = web.DownloadString("\\server\fileshare\1DTools\Version.txt")
Dim CurrentApp As String = versionInfo.FileVersion 'Gets the applications current version
If System.IO.File.Exists("\\server\fileshare\1DTools\Version.txt") = False Then
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
Else
If CurrentApp < LatestVersion Then 'If the applications current version is less than the Latest version it will update
System.IO.File.Delete("C:\Apps\1DTools\1DTrayMenu.exe") 'remove old version of file
System.IO.File.Delete("C:\Apps\1DTools\ThePrecious.exe") 'remove old version of file
System.IO.File.Delete("C:\Apps\1DTools\1DTools.ini") 'remove old version of file
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\1DTrayMenu.exe", "C:\Apps\1DTools\1DTrayMenu.exe")
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\ThePrecious.exe", "C:\Apps\1DTools\ThePrecious.exe")
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\1DTools.ini", "C:\Apps\1DTools\1DTools.ini")
MsgBox("Your 1DTrayMenu has been updated!" & vbNewLine & "The new version will now start") 'telling the user the app will close
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
Else
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
End If
End If
End Sub
End Class
Thank you for your assistance in advance...
I have included the code (below). I have coloured the line in red that I think is causing the error and as this happens before I can insert an error trap to deal with the absence of the network share, I can't see how to stop the problem. Is there a simple solution that will prevent the error? Any help will be greatly appreciated as this one is stumping me.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim web As New WebClient 'To be able to download the content from the latest version file you have stored.
Dim versionInfo As FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo("C:\Apps\1DTools\1DTrayMenu.exe")
Dim LatestVersion As String = web.DownloadString("\\server\fileshare\1DTools\Version.txt")
Dim CurrentApp As String = versionInfo.FileVersion 'Gets the applications current version
If System.IO.File.Exists("\\server\fileshare\1DTools\Version.txt") = False Then
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
Else
If CurrentApp < LatestVersion Then 'If the applications current version is less than the Latest version it will update
System.IO.File.Delete("C:\Apps\1DTools\1DTrayMenu.exe") 'remove old version of file
System.IO.File.Delete("C:\Apps\1DTools\ThePrecious.exe") 'remove old version of file
System.IO.File.Delete("C:\Apps\1DTools\1DTools.ini") 'remove old version of file
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\1DTrayMenu.exe", "C:\Apps\1DTools\1DTrayMenu.exe")
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\ThePrecious.exe", "C:\Apps\1DTools\ThePrecious.exe")
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\1DTools.ini", "C:\Apps\1DTools\1DTools.ini")
MsgBox("Your 1DTrayMenu has been updated!" & vbNewLine & "The new version will now start") 'telling the user the app will close
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
Else
Process.Start("c:\apps\1DTools\1DTrayMenu.exe")
End 'exits application
End If
End If
End Sub
End Class
Thank you for your assistance in advance...