很多软件都支持自动升级,WINDOWS自身也有自动更新的功能。不知道哪位大侠知道自动升级的原理是什么?用到了什么技术?
有源码的就最好了,方便的话给我一份 小弟将不胜感激 [email protected]

解决方案 »

  1.   

    原理最简单了,就是做起来要考虑的细节多些
    1,验证版本
    2,下载要更新的文件,单独EXE操作这块,以方便后边的关闭程序,重新打开
    3,下载完毕后,重新打开程序
      

  2.   

    1,验证版本
            static void Main() {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault( false );
                /* 2,4,6 检查升级 */
                if( ( DateTime.Now.DayOfWeek == DayOfWeek.Tuesday
                    || DateTime.Now.DayOfWeek == DayOfWeek.Thursday
                    || DateTime.Now.DayOfWeek == DayOfWeek.Saturday )
                    && Version.CheckVersion() ) {
                    //升级
                    UpdateVersion frm = new UpdateVersion();
                    if( frm.ShowDialog() == DialogResult.OK ) {
                        Application.Run( new TstringCodeFactory() );
                    }
                } else {
                    //打开主窗口
                    Application.Run( new TstringCodeFactory() );
                }
            }
      

  3.   

    2,下载要更新的文件
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Xml;
    using Tstring.Core.Util;
    using System.Configuration;
    using System.Diagnostics;
    using System.IO;namespace Tstring.Core.Builder {
        public partial class UpdateVersion : Form {
            #region field
            string fileName = "Tstring.Core.Builder.exe";
            #endregion
            #region property
            public int Version { get; set; }
            #endregion
            #region constructor
            public UpdateVersion() {
                InitializeComponent();
                this.StartPosition = FormStartPosition.CenterScreen;
                this.FormBorderStyle = FormBorderStyle.None;
                this.ShowInTaskbar = true;
                this.Text = "自动更新";
            }
            #endregion        #region event
            protected override void OnLoad( EventArgs e ) {
                FileDownLoad file = new FileDownLoad( ConfigurationManager.AppSettings[ "UpdateExe" ], fileName );
                file.OnProgress += new DownloadProgressHandler( file_OnProgress );
                file.OnComplete += new DownloadCompleteHandler( file_OnComplete );
                file.Start();
                base.OnLoad( e );
            }        void file_OnComplete( string filename, byte[] data ) {
                if( data != null ) {
                    if( !Directory.Exists( "bak" ) ) Directory.CreateDirectory( "bak" );
                    if( File.Exists( fileName ) ) File.Move( fileName, Guid.NewGuid().ToString() + ".exe" );                using( FileStream stream = new FileStream( fileName, FileMode.CreateNew ) ) {
                        using( BinaryWriter writefile = new BinaryWriter( stream ) ) {
                            writefile.Write( data );
                        }
                    }
                }            this.DialogResult = DialogResult.OK;
            }        void file_OnProgress( string filename, int totalBytes, int bytesRead ) {
                this.Invoke( new Action( () => { this.label1.Text = string.Format( "正在更新:{0}/{1} bytes", bytesRead, totalBytes ); } ) );
            }
            #endregion
        }
    }
      

  4.   

    帮你找了两篇文章:
    Application Auto Update Revisited
    http://www.codeproject.com/KB/vb/Auto_Update_Revisited.aspxApplication Auto Update in VB.NET
    http://www.codeproject.com/KB/vb/autoupdate.aspx
    都有源码的
      

  5.   

    这里是验证版本
            public class Version {
                public static int Verstion { get; set; }
                public static bool CheckVersion() {
                    string path = System.Configuration.ConfigurationManager.AppSettings[ "UpdatePath" ];
                    string version = System.Configuration.ConfigurationManager.AppSettings[ "Version" ];
                    if( !string.IsNullOrEmpty( path ) ) {
                        XmlDocument xml = new XmlDocument();
                        try {
                            xml.Load( path );
                            XmlNode node = xml.SelectSingleNode( "/version" );
                            if( node != null ) {
                                System.Configuration.ConfigurationManager.AppSettings[ "Version" ] = node.InnerText;
                                return node.InnerText != version;
                            }
                        } catch(Exception exp) {
                            Log.Error( exp );
                            return false;
                        }
                    }
                    return false;
                }
            }
    其中配置文件里配置相关的路径等
      

  6.   

    参考http://www.cnblogs.com/freeliver54/archive/2008/07/21/1247327.htmlhttp://www.cnblogs.com/jenry/archive/2006/08/15/477302.html
      

  7.   

    可以用ClickOnce,如果客户端有一些客户自己的配置文件的话,每次更新后就会覆盖
    我现在用的方法是:
    服务端一个配置文件,客户端一个配置文件
    程序启运时读取客户端的配置文件版本号与服务器配置文件的版本号对比,如果不一样就下载服务器的(服务端是将配置文件和要下载的文件那一个虚拟目录)我下载文件格式是一个压缩包(包括配置文件一同下载下来),下到客户端后新建一个临时然后自动解压,待点击【完成】后,将解压的文件Copy覆盖客户端对应的文件(注意配置文件最后复制,如果你配置文件先复制的话中间出现异常,其它文件没复制,这时客户端配置文件与服务端配置文件一样了,下次不会自动更新,最后复制就不会有这个问题),
      

  8.   

    最近刚做了个,不外乎就是这几步:
    1.读取服务器上xml文件,里面有版本信息和需要下载的文件列表.
    2.验证版本,下载相应文件,我比较懒,版本一不对就全下载,楼主可以对各个文件单独处理.
    3.打开主程序.
      

  9.   

    看看这个http://rookiesoft.yourblog.org/logs/222941.html
      

  10.   

    通过web services和WebClient查询服务器实现自动更新参考
      

  11.   

    #Private Sub TmSendStatusRequest_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles TmSendStatusRequest.Elapsed
            TmSendStatusRequest.Stop()
            Dim ReturnValue As Boolean = False
            Try
                If (IsConnected = True) Then
                    ReturnValue = StatusRequest()
                    Exit Try
                End If
            Catch ex As Exception
                EventLog.WriteEntry("PVGAFDS\TmSendStatusRequest_Elapsed", ex.Message.ToString() + Constants.vbCrLf + ex.StackTrace.ToString(), EventLogEntryType.Error)
            Finally
            End Try
            TmSendStatusRequest.Start()
        End Sub
      

  12.   

    #Private Sub TmSendStatusRequest_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles TmSendStatusRequest.Elapsed
            TmSendStatusRequest.Stop()
            Dim ReturnValue As Boolean = False
            Try
                If (IsConnected = True) Then
                    ReturnValue = StatusRequest()
                    Exit Try
                End If
            Catch ex As Exception
                EventLog.WriteEntry("PVGAFDS\TmSendStatusRequest_Elapsed", ex.Message.ToString() + Constants.vbCrLf + ex.StackTrace.ToString(), EventLogEntryType.Error)
            Finally
            End Try
            TmSendStatusRequest.Start()
        End Sub
      

  13.   

    我做過一個自殺更新然後重啟的測試,你從下面的鏈接過去看看
    http://www.cnblogs.com/jinliangliu/archive/2009/02/26/1398754.html
      

  14.   

     
    //WINDOWS模拟升级
    //升级程序.
    private void button1_Click(object sender, EventArgs e)
            {
                Process[] ps = Process.GetProcesses();
                string path = "";
                foreach (Process var in ps)
                {
                    if (var.ProcessName == "WindowsApplication2")
                    {
                        path = var.MainModule.FileName;
                        var.Kill();
                        break;
                    }
                }
                MessageBox.Show(path);
                if (delfile(path))
                {
                    File.Delete(path);
                    File.Copy(@"D:\temp\系统升级\newversion\WindowsApplication2\WindowsApplication2\bin\Debug\WindowsApplication2.exe", path);
                    Process.Start(path);
                }
               
            }        static bool delfile(string path)
            {
                bool tag = false;
                AppDomain ad = AppDomain.CreateDomain("dll test");
                myclass obj = (myclass)ad.CreateInstanceFromAndUnwrap(@"update.exe", "update.myclass");
               if (obj.LoadAssembly(path))
                 {   tag = true;}
                AppDomain.Unload(ad);
                obj = null;
                return tag;
            }
        }    public class myclass : MarshalByRefObject
        {
             public bool LoadAssembly(string asspath)
            {
                bool tag=false;
                Assembly  assembly = Assembly.LoadFrom(asspath);
                if (assembly.GetName().Version.ToString() == "1.0.0.0")
                    tag = true;
                return tag;
            }     }///////////////////////////
    原始版本:1.0版本的WindowsApplication2.exe
     private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("this is version 1.0");
            }//////////////////////////////
    升级后的版本:2.0版本的WindowsApplication2.exe
     private void button1_Click(object sender, EventArgs e)
            {
                MessageBox.Show("this is version 2.0");
            }
      

  15.   

    改成WEB就只需要将要更新的程序集的信息发到服务器,然后获取一个信息,看是否需要更新
    需要就将要更新的文件通过webclient下载到本地再更新安装路径下的文件,删除下载的文件即可