Thomas
Thomas

Reputation: 34208

Automatic update a Windows application

How do I develop my Windows application so it will auto update on the client machine, like Firefox, Skype, etc.?

Is there any simple approach or any open source library which help me to do it just following some steps or a few lines of code?

Upvotes: 13

Views: 54032

Answers (9)

Michael Herrmann
Michael Herrmann

Reputation: 5013

The most popular frameworks are:

  • Google Omaha - This is what Chrome uses. Very powerful.
  • Squirrel - This is used in Electron applications. Easy to use but can't update machine-wide installations. Also, no graphical update notifications.
  • WinSparkle - Gives you graphical update notifications. But less mature than Squirrel.
  • AutoUpdater.NET - Both graphical and silent updates. Similar to Squirrel and WinSparkle.

I've taken these links from this article. It goes into more details about the pros and cons of each of the frameworks.

Upvotes: 4

jrz.soft.mx
jrz.soft.mx

Reputation: 161

Use MD5-Update it easy only need add 5 lines at your application, no configuration need in your app only add library and publish the files.

MD5-Update

1. Your need a web server with PHP for publish your files please include updt.exe.

WebServer

2. Add index.php for make list of update files. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.

<?php
$_dat = array();
$_dir=new RecursiveDirectoryIterator(".");
foreach (new RecursiveIteratorIterator($_dir) as $_itm) {
    $_fil = str_replace(".".DIRECTORY_SEPARATOR, "", $_itm);
    if(!is_dir($_fil) && $_fil != "index.php"){     
        $_dat[]=array('StrFil' => "$_fil", 'StrMd5' => strtoupper(md5_file($_fil)), 'lonSiz' => filesize($_fil));
    }
}
echo json_encode($_dat, JSON_UNESCAPED_UNICODE);
?>

enter image description here

3. Add nuget repository at your proyect

PM> Install-Package MD5.Update

4. Call the library when your app stars, with your update folder url, update all files and download your new app on updt folder, for replace your app need updt.exe

string strUrl = "http://yourdomain.com/app/";
if (MD5Update.MD5Update.Check(strUrl, true))
{
    Process.Start(AppDomain.CurrentDomain.BaseDirectory + @"updt.exe", AppDomain.CurrentDomain.FriendlyName + " " + Process.GetCurrentProcess().ProcessName);
    Application.Exit();
}

enter image description here

enter image description here

5. updt.exe for replace the current app with the new app updt folder to app. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.

try
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    List<string> lisArg = Environment.GetCommandLineArgs().ToList();
    if (lisArg.Count < 2)
    {
        MessageBox.Show("Please provide App Excutable Name and Procees name");
        Application.Exit();
        return;
    }
    string strAppName = lisArg[1];
    string strAppProcees = lisArg[2];
    Process[] lisPro = Process.GetProcessesByName(strAppProcees);
    foreach (Process Pro in lisPro)
    {
        if (Pro.Id != Process.GetCurrentProcess().Id)
        {
            Pro.Kill();
            Thread.Sleep(1000);
        }
    }
    string strAppMain = AppDomain.CurrentDomain.BaseDirectory + strAppName;
    string strAppUpdate = AppDomain.CurrentDomain.BaseDirectory + @"updt\" + strAppName;
    if (!File.Exists(strAppMain))
    {
        MessageBox.Show("App Excutable dosent exists");
        Application.Exit();
        return;
    }
    if (!File.Exists(strAppUpdate))
    {
        MessageBox.Show("App Excutable Updated dosent exists");
        Application.Exit();
        return;
    }
    File.Copy(strAppUpdate, strAppMain, true);
    long fileSize = 0;
    FileInfo currentFile = new FileInfo(strAppMain);
    while (fileSize < currentFile.Length)
    {
        fileSize = currentFile.Length;
        Thread.Sleep(1000);
        currentFile.Refresh();
    }
    Process.Start(strAppMain);
}
catch (Exception Ex)
{
    MessageBox.Show("An error ocurred");
    File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"updt_" + DateTime.Now.ToString("yyyyMMddTHHmmss")  + " .txt", Ex.ToString());
    Application.Exit();
}

Upvotes: 3

Lev Yastrebov
Lev Yastrebov

Reputation: 991

While ClickOnce is simple and it resurrected for .NET 5, it still has a lot of limitations, so I found out that nowadays better option exists: you could use included in Windows 10 mechanism for app delivery called AppInstaller by packaging your app in MSIX bundle or package.

I covered my findings related to the topic in this answer

Upvotes: 0

Uri Abramson
Uri Abramson

Reputation: 6175

How about System Center 2012 Configuration Manager?

Upvotes: 0

dexter
dexter

Reputation: 7213

There is also the Update Block in the Ent Lib by msft.

Upvotes: 2

Giorgi
Giorgi

Reputation: 30883

You can use wyUpdate or .NET Application Updater Component

Upvotes: 3

Martin Buberl
Martin Buberl

Reputation: 47164

ClickOnce is what you're searching for.

You might also find these SO questions interesting (which offers some different solutions):

Upvotes: 10

Dani
Dani

Reputation: 15079

try microsoft clickonce technology

(in MSDN)

Upvotes: 3

Related Questions