实现功能:通过网站更新用户的软件,需要联网,也可以通过本地网站更新局域网用户软件。

根本实现:1.一个网站(我用的是自己的www.aq36.xyz ,本地就可以,可以用localhost)然后运行update.exe->{通过update.xml获取网址,然后查看当前版本号和网站的server.xml最高版本号对比。然后判断是否更新}。

2.更新就下载zip文件,解压替换并删除。

3.更新update.xml文档版本信息,跟新结束。

主要代码:

1.解析xml文件:

/// <summary>
/// 载入并解析XML
/// </summary>
private void LoadXml()
{
XmlDocument document = new XmlDocument();
try
{
document.Load(updateurl + "Server.xml");
XmlNode node = document.SelectSingleNode("//updates"); //获取最新版本号
version = Convert.ToInt32(node.Attributes["version"].Value); //所有需要升级文件大小,文件列表,sql列表
XmlNodeList updateList = document.SelectNodes("//updates//update");
foreach (XmlNode n in updateList)
{
long tempVersion = Convert.ToInt32(n.Attributes["version"].Value);
long tempSize = Convert.ToInt64(n.Attributes["size"].Value);
if (tempVersion > localversion && tempVersion <= version)
{
allsize += tempSize;
versions.Add(tempVersion.ToString());
//获取升级文件列表
XmlNodeList fileList = n.SelectNodes("//update[@version='" + tempVersion + "']//files//file");
foreach (XmlNode n1 in fileList)
{
files.Add(n1.InnerText);
}
//获取执行的SQL语句列表
XmlNodeList sqlList = n.SelectNodes("//update[@version='" + tempVersion + "']//sqls//sql");
foreach (XmlNode n2 in sqlList)
{
sqls.Add(n2.InnerText);
}
//升级的提示信息
XmlNodeList msgList = n.SelectNodes("//update[@version='" + tempVersion + "']//msg");
foreach (XmlNode n3 in msgList)
{
msg += string.Format(CultureInfo.InvariantCulture, "版本【{0}】 {1}", new object[] { tempVersion, n3.InnerText.Replace("\r\n\t\t", "") }) + "\r\n";
}
} } }
catch (Exception e)
{
//Console.WriteLine(e.Message);
MessageBox.Show("连接升级服务器失败,请重试!", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

2.下载文件:

 private void DownloadFile(int index)
{
try
{
downindex++;
filename = files[index];
//LabelNow.Text = "开始下载版本【" + versions[index] + "】" + filename;
LabelAll.Text = string.Format(CultureInfo.InvariantCulture, "升级进度 {0}/{1} [ {2} ]", new object[] { downindex, files.Count, this.ConvertSize(allsize) });
PBNow.Value = ;
downWebClient.DownloadFileAsync(new Uri(updateurl + filename), Application.StartupPath + "/temp/" + filename); }
catch (WebException exception)
{
MessageBox.Show(exception.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

3.开始升级:

 private void StartUpdate()
{
if (localversion >= version)
{
UpdateCompleted();
return;
}
this.downWebClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
this.downWebClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
if (this.allsize == 0L || files == null || files.Count == )
{
this.UpdateCompleted();
}
if (files != null && files.Count > )
{
DownloadFile();
} }

4.下载完成并更改update.xml

  private void DownloadFileCompleted(object wcsender, AsyncCompletedEventArgs ex)
{
if (ex.Error != null)
{
MessageBox.Show(ex.Error.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
else
{
if (File.Exists(Application.StartupPath + @"\" + this.filename))
{
File.Delete(Application.StartupPath + @"\" + this.filename);
}
File.Move(Application.StartupPath + @"\temp\" + this.filename, Application.StartupPath + @"\" + this.filename);
new FastZip().ExtractZip(Application.StartupPath + @"\" + this.filename, Application.StartupPath + @"\", "");
File.Delete(Application.StartupPath + @"\" + this.filename);
this.downedsize += this.filesize;
if (this.files.Count > this.downindex)
{
this.DownloadFile(this.downindex);
}
else
{
XmlTextWriter writer = new XmlTextWriter(Application.StartupPath + @"\update.xml", null)
{
Formatting = Formatting.Indented,
Indentation =
};
writer.WriteStartDocument();
writer.WriteStartElement("update");
writer.WriteStartElement("ProcessName");
writer.WriteString(this.ProcessName);
writer.WriteEndElement();
writer.WriteStartElement("version");
writer.WriteString(this.version.ToString());
writer.WriteEndElement();
writer.WriteStartElement("url");
writer.WriteString(this.updateurl);
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
writer.Close();
if (!string.IsNullOrEmpty(this.msg))
{
MessageBox.Show(this.msg, "升级提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
this.UpdateCompleted();
}
}
}

跟新进度条效果图:

更新前:

更新后:

一些文档代码图解:

1.本地update.xml

2.网站server.xml

代码粗糙,只是一个简单的demo,简单参考一下,有错误及时联系我。

百度网盘源码加文件:http://pan.baidu.com/s/1qYe2Vgg

通过web对.exe程序进行更新和修改的更多相关文章

  1. nw.js桌面程序自动更新(node.js表白记)

    Hello Google Node.js 一个基于Google V8 的JavaScript引擎. 一个伟大的端至端语言,或许我对你的热爱源自于web这门极富情感的技术吧! 注: 光阴似水,人生若梦, ...

  2. .Net桌面程序自动更新NAppUpdate

    自动更新介绍 我们做了程序,不免会有版本升级,这就需要程序有自动版本升级的功能.应用程序自动更新是由客户端应用程序自身负责从一个已知服务器下载并安装更新,用户唯一需要进行干预的是决定是否愿意现在或以后 ...

  3. Python编写的桌面图形界面程序实现更新检测和下载安装

    在Python中我们有很多种方案来编写桌面图形用户界面程序,譬如内置的 Tkinter .强大的 PyQt5 和 PySide2 ,还有 wxPython .借助这些或内置或第三方的模块,我们可以轻松 ...

  4. Docker容器环境下ASP.NET Core Web API应用程序的调试

    本文主要介绍通过Visual Studio 2015 Tools for Docker – Preview插件,在Docker容器环境下,对ASP.NET Core Web API应用程序进行调试.在 ...

  5. 在docker中运行ASP.NET Core Web API应用程序

    本文是一篇指导快速演练的文章,将介绍在docker中运行一个ASP.NET Core Web API应用程序的基本步骤,在介绍的过程中,也会对docker的使用进行一些简单的描述.对于.NET Cor ...

  6. <转>exe & dll自我更新

    exe & dll自我更新 分类: c/c++ 2008-10-16 22:07 756人阅读 评论(1) 收藏 举报 exedlldelayapi游戏 exe与dll的自我更新     在改 ...

  7. 本地json文件的编辑器,node-webkit开发的exe程序

    首发:个人博客,更新&纠错&回复 在昨天的dota契合度计算器中,用到了dota英雄数据和dota玩家数据这两个数据库,为了便于网页应用使用,这两个数据库的存储格式是json,即her ...

  8. HTML5 Web缓存&运用程序缓存&cookie,session

    在介绍HTML5 web缓存前,来认识一下cookie和session: session: 由于HTTP是无状态的,你是谁?你干了什么?抱歉服务器都是不知道的. 因此session(会话)出现了,它会 ...

  9. Linux,在不使用U盘的情况下使用wubi.exe程序在Win7上安装ubuntu-14.04.3版系统

    本文介绍如何在不使用U盘的情况下使用wubi.exe程序在Win7上安装ubuntu-14.04.3版系统. 花了一天的时间终于安装上了Ubuntu14.04,过程坎坷,是血泪史,开始报“cannot ...

随机推荐

  1. .NET 知识整理笔记

    本文纯属自己理解着写的,如果有什么错误或者不全面希望读者能够加以补充!~ 1.Web.Config配置文件的节点操作. 在Web.Config中写入. <configuration> &l ...

  2. 第一个小程序:helloWord

    public class HelloWorld {     public static void main(String []args){          System.out.println(&q ...

  3. iOS下的界面布局利器-MyLayout布局框架

      Swift:TangramKit: https://github.com/youngsoft/TangramKit OC:MyLayout: https://github.com/youngsof ...

  4. 【原创】Ionic单页应用跳转外链,构造路由返回的解决办法及代码

    在开发广汽菲克微信企业号的填单审批webApp的时候出现了一个问题: 单据是带有附件的,而且存在各种不同的格式,需要后台处理后给前台链接地址,点击预览,微信浏览器的特性就是只能存在一个浏览器窗口, 这 ...

  5. JSP +++SERVIET总复习

    一. JSP基础概念 软件架构 B/S架构:Browser/Server,浏览器-服务器 最大的优点就是:一次部署,处处访问. C/S架构:Client/Server,客户端-服务器 功能.事件丰富, ...

  6. Node.js + React + MongoDB 实现 TodoList 单页应用

    之前用 Ant Design 开发了一个项目,因此对 React 的特性有了一定的了解,React 使用封装组件的思想,组件各自维护自己的状态和 UI, 组件之间通过 props 传递数据和方法.当状 ...

  7. Jmeter接口压力测试

    SOAP百科:Soap简单对象访问协议,是交换数据的一种协议规范,是一种轻量的.简单的.基于XML(标准通用标记语言下的一个子集)的协议,它被设计成在WEB上交换结构化的和固化的信息.webServi ...

  8. JavaScript tips:数组去重

    1.实现目标:数组去重 2.实现思路: (1)创建新数组. (2)遍历原数组,判断当前被遍历元素是否存在于新数组,如果存在于新数组,则判断当前被遍历元素是重复的:如果不存在于新数组,则判断当前被遍历元 ...

  9. 提交任务到Spark

    1.场景 在搭建好Hadoop+Spark环境后,现准备在此环境上提交简单的任务到Spark进行计算并输出结果.搭建过程:http://www.cnblogs.com/zengxiaoliang/p/ ...

  10. 谈谈在DevOps实践中,感觉最重要的这三个技术……

    从国内众多DevOps实践中,我们能看到下面三个技术尤其重要和火热: 容器:容器从根本上解决了软件对环境的依懒性,解决了各个环境之间的差异问题:它可以加速部署的速度,提高部署的效率:降低部署的成本.容 ...