Results 1 to 5 of 5

Thread: Update software function doesn't work if software is already open

  1. #1

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Update software function doesn't work if software is already open

    I've a function that check update for my application. I've two mode for execute this function, in the first time that the application's start and in the tooltip menu. If I execute the software for the first time all working good, the update is found , but if I press on my button in the tooltip menu the same function (the exact function) not working. In particular the update is found but the software for download it (infinity blue) doesn't start. This is the function:

    Code:
    Dim MyAppName As String = "Sund.exe"
            Dim url As String = "www.site.com/update/" & "FileUpdates371.php"
            Dim pageRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
            Dim pageResponse As WebResponse = pageRequest.GetResponse()
            Dim filelist As String : Dim Mainlist As String
            Using r As New StreamReader(pageResponse.GetResponseStream())
                filelist = r.ReadToEnd
                If Not IO.File.Exists(Application.StartupPath & "\" & "Updates") Then
                    IO.File.WriteAllText(Application.StartupPath & "\" & "Updates", filelist)
                End If
                Dim sr As New StreamReader(Application.StartupPath & "\" & "Updates")
                Mainlist = sr.ReadToEnd
                Dim FileLines() As String = filelist.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
                Dim MainLines() As String = Mainlist.Split(New String() {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
                If Not Mainlist = filelist And Not FileLines.Length < MainLines.Length Then
                    Dim answer As DialogResult
                    answer = MessageBox.Show("Update available", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                    If answer = vbYes Then
                        Dim App As New Process
                        App.StartInfo.FileName = Application.StartupPath & "\" & "InfinityBlue.exe"
                        App.StartInfo.Arguments = "Update|" & MyAppName & "|" & url
                        App.Start()
                        Me.Close()
                    End If
                End If
            End Using
            If My.Computer.FileSystem.FileExists(Application.StartupPath & "\" & "InfinityBlueUpdate.exe") Then
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\" & "InfinityBlue.exe", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                My.Computer.FileSystem.RenameFile(Application.StartupPath & "\" & "InfinityBlueUpdate.exe", "InfinityBlue.exe")
            End If
    I've also tried to catch the exception and there isn't exception. Why happean this?

  2. #2
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Update software function doesn't work if software is already open

    If you are trying to write an auto updater for your app from within the app you will have issues.
    Note: a file in use on a Windows PC cannot be deleted or altered while it is in use.

    I found many hits on the topic. Here is one.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  3. #3
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: Update software function doesn't work if software is already open

    Is it the downloading part or the updating part that is not working? i.e. is it after you click "Yes" to update or before.

    I would be concerned with the Process, you're starting the process and then closing the source application. If the process starts and the application is not yet closed, then as Gruff says the update will most likely fail. If it fails it may also leave an orphaned process (check using Task Manager).

    The way I have dealt with this in the past is to use a process that starts a standalone updater, which checks the main app is closed before doing anything.


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  4. #4

    Thread Starter
    Addicted Member JackIlPazzo's Avatar
    Join Date
    Oct 2014
    Posts
    183

    Re: Update software function doesn't work if software is already open

    The main application isn't close because I've an external updater. I want find the solution to close the main app and start the updater. The code in the first post works only in the form main lo ad, but if I execute the code manually this doesn't working..

  5. #5
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: Update software function doesn't work if software is already open

    If you read the first link they talk about different ways around the problem.
    One I believe is to have the main program rename itself. I guess that is allowed if your user has admin privilege.
    After that you download the new Exe file. Rename it if you need to and shut down your app.
    When the user restarts the new Exe will launch.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width