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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM