Solved

auto update winforms vb.net application

Posted on 2010-08-29
10
1,759 Views
Last Modified: 2012-05-10
Hi,

I ma working with a winforms application. Every time i create a new uild, insted of going and installing on each pc is there any way i can update automatically?
I will post a build on a web site an the application should check the website upon each new login if there is aa new version.
If a new version exists, it sould update else cntinue with the current update.

Is it possible? I am using setup  and deployment process. I do not want to use click once deployment process.


Thanks.
0
Comment
Question by:rowternet
  • 6
  • 3
10 Comments
 
LVL 2

Expert Comment

by:ozi_lion
ID: 33552302
Hi, It is possible to do that by several ways. Yiu can compare version numbers of current application version number and new one if different it is an update. Also you can put a text file contains an update informations like if file contains 1 there is an update or if 0 there is no new update. you can check new version onload or in some periods or let your client to choose when they want to check for update. best way i think put a small file contains new version information to your ftp and let your client application to read this file and compare with current version installed. if number in file is bigger than installed one then you can download and install update program.

hope it helps. i am doing this with VB6 using inet and works great.


0
 

Author Comment

by:rowternet
ID: 33556362
So far this i what i have:
I do not have the site where i upload my project. I have to finish the rest tomorrow.



 Private Sub getsourcecode()
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.mysite.com/Information/myMgrVersion/myMgrVersion.htm")
        Dim response As System.Net.HttpWebResponse = request.GetResponse
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
        Dim newerversion As String = sr.ReadToEnd
        Dim currentversion As String = Application.ProductVersion
        If newerversion.Contains(currentversion) Then
            MessageBox.Show("No new version")
        Else
            MessageBox.Show("Newer version is available")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        getsourcecode()

    End Sub
    Private Sub downloadfile()
        Dim client As New Net.WebClient
        client.DownloadFile("www.mysite.com/Information/Tr", "Sr.exe")


    End Sub
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33556384
You're not going to be able to update the application while it's in memory, so in my estimate you are going to need to create a separate .exe which your main app launches. This app would check for the update and if found, kill the main app, get the update, and then relaunch the main app once the file has been downloaded and installed. You need to settle on how you determine whether a new version is available, but it appears you have that covered.  :)
0
 

Author Comment

by:rowternet
ID: 33562041
kaufmed and ozlion,

How do i kill the main app if a new version is detected ? and how do i install the new one when the current version is running?

Can you provde code or any links which explain this process?

Thanks.
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 33562988
You would have code in your main app that would launch the update app (Example 1). If the update app detects a new version, it would loop through the running processes and kill all main app instances (Example 2). In Example 2, "WindowsFormsApplication.vshost" is the name of the process (less the ".exe") that is acting as my main app. You would of course substitute in your application name there.
/// <summary>
/// Example 1
/// </summary>
/// <remarks>
/// This is in your main app
/// </remarks>
public void CheckForUpdates()
{
    System.Diagnostics.Process.Start(@"C:\path\to\your\update\app.exe");
}

/// <summary>
/// Example 2
/// </summary>
/// <remarks>
/// This is in your update app
/// </remarks>
public void KillAppInstances()
{
    foreach (var proc in System.Diagnostics.Process.GetProcessesByName("WindowsFormsApplication2.vshost"))
    {
        proc.Kill();
    }
}

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:rowternet
ID: 33563978
Hi, if i have to use a savedialog box for this how can i do this?
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 33576341
>>  if i have to use a savedialog box for this how can i do this?

Use it for what?
0
 

Author Comment

by:rowternet
ID: 33802175
Hi Kaufmed,
I am almost done with the code for auto updating.
when i try to kill the process, using what you gave earlier,

  For Each proc As var In System.Diagnostics.Process.GetProcessesByName("")
            proc.Kill()
        Next

I am geting a error : Type 'var' isnot defined.
why am i getting this error?

thanks
0
 

Author Comment

by:rowternet
ID: 33809078
Dont worry. I have it working this way
Private Shared Sub killApp()

        'MessageBox.Show("Killing Started")

        Dim myprocess() As Process

        Dim proc As Process

        myprocess = Process.GetProcesses

        Dim mystring As String = Nothing

        Dim myprocstring As String = Nothing

       

        myprocstring = "System.Diagnostics.Process (ShahTransportationMgrProject)"

        'MessageBox.Show(myprocstring.Length)

        Try

            For Each proc In myprocess

                mystring = proc.ToString

                Dim abc As Integer = mystring.CompareTo(myprocstring)

                If abc = 0 Then

                    proc.Kill()

                End If

            Next

        Catch ex As Exception

            MessageBox.Show(ex.ToString, "Warning: Killing Started")

        End Try



    End Sub

Open in new window

0
 

Author Closing Comment

by:rowternet
ID: 33809099
Thanks
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now