C#Winform实现⾃动更新服务端:
[WebMethod]
public string GetNewService(string version)
{
//通过版本号进⾏⽐较
if (version == "v1.0")
{
return"没有新版本!";
}
else
{
return@"E:\"; //返回⼀个地址,这个⾥⾯存有新版本!
}
}
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;
webservice实现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