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