Question Problems with auto-update when no network access is available

Georgeu

New member
Joined
Jan 29, 2014
Messages
2
Programming Experience
Beginner
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...


 
You have My.Computer.Network.IsAvailable property to detect if connected to a network.
If connected while that server is not present, you can Try-Catch the call to catch the WebException.
 
JohnH

Thank you for your help with this problem. It gave me a fresh perspective on the problem and I suddenly realised that I needed to split the Updater from the Network accessibility checker. That way, if the Network install point is available, it will call the update checker. If the network resource is not accessible it doesn't even try to do the updater and just starts the Tray menu. So It has resolved the issues. I have included the revised code below for anyone that is interested:

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
On Error Resume Next
If System.IO.File.Exists("\\server\fileshare\Version.txt") = False Then 'Test if Install.Point is available
Process.Start("c:\apps\1DTools\1DTrayMenu.exe") 'If not available, just run local copy of 1DTrayMenu then
End 'exit application
Else
Call Update_TrayMenu() 'If Install Point is accessible, then run the update checker
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 'exit application
End If
End Sub
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub Update_TrayMenu()
Dim LocalTrayMenu As FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo("C:\Apps\1DTools\1DTrayMenu.exe")
Dim ServerTrayMenu As FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo("\\server\fileshare\1DTrayMenu.exe")
Dim LatestTrayMenu As String = ServerTrayMenu.FileVersion 'Gets the applications current version
Dim CurrentTrayMenu As String = LocalTrayMenu.FileVersion 'Gets the applications current version
If CurrentTrayMenu < LatestTrayMenu Then 'If the applications current version is less than the Latest version it will update, otherwise just start 1DTrayMenu.exe
System.IO.File.Delete("C:\Apps\1DTools\1DTrayMenu.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\1DTrayMenu.exe", "C:\Apps\1DTools\1DTrayMenu.exe")
My.Computer.Network.DownloadFile("\\server\fileshare\1DTools\1DTools.ini", "C:\Apps\1DTools\1DTools.ini")
Else
End If
End Sub
 
Back
Top