Solved

auto update winforms vb.net application

Posted on 2010-08-29
10
1,789 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 75

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 75

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

912 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

16 Experts available now in Live!

Get 1:1 Help Now