標籤:
服務端:
[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
C#Winform實現自動更新