服務端:服務器
[WebMethod] public string GetNewService(string version) { //經過版本號進行比較 if (version == "v1.0") { return "沒有新版本!"; } else { return @"E:\QMDownload\CashTest.exe"; //返回一個地址,這個裏面存有新版本! } }
客戶端:ide
//自動更新開始 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()); } } //自動更新結束