C#Winform实现自动更新

服务端:

  [WebMethod]
        public string GetNewService(string version)
        {
            //通过版本号进行比较
            if (version == "v1.0")
            {
                return "没有新版本!";
            }
            else
            {
                return @"E:\QMDownload\CashTest.exe"; //返回一个地址,这个里面存有新版本!
            }
        }
View Code

 

客户端:

  //自动更新开始
            Juran.CenterCash.WebService.UpdateService.WebService server = new WebService.UpdateService.WebService();
            string path = server.GetNewService("v1.x");
            if (path == "没有新版本!")
            {
            }
            else
            {
                try
                {
                    WebClient wClient = new WebClient();
                    wClient.DownloadFile(path, "D:\\1.exe"); //下载服务器的文件到本地,取名为1.exe
                    Process pro = new Process();
                    string fileName = @"D:\\1.exe";
                    string para = "";
                    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(fileName, para);
                    pro.StartInfo = myProcessStartInfo;
                    pro.Start();
                    while (!pro.HasExited)
                    {
                        pro.WaitForExit();
                    }

                    int returnValue = pro.ExitCode;
                    if (returnValue == 0)
                    {
                        MessageBox.Show("更新成功,请启动程序!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            //自动更新结束
View Code

 

posted @ 2015-07-08 16:42  hometown  阅读(2691)  评论(1编辑  收藏  举报