c#winform制作安装程序,程序升级问题怎么解决? c#winform制作安装程序,程序升级问题怎么解决? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我用vs2005 的ClickOnce 发布方法 可以自动更新!但是 就是没有卸载方式,,,,郁闷的我帮忙解决下 有没有代码?如果有的话请你给我发一份OK不?先谢谢了我的邮箱是[email protected] csdn的下载里面好像有,我记得以前看过,lz搜搜吧,这个也不难写的 好像不是这样的吧,winform的程序似乎没有办法更新吧,更新之后需要重新安装,是需要重新编译的,更新上去的是无法自动编译的 winform 程序只用更新dll就可以完成。建议参考如下例子:http://www.cnblogs.com/glacier/archive/2009/03/27/1423542.html 安装包在安装的时候先像注册表里写如软件版本号,当然也可以用ini,config甚至你不怕慢也可以用access.然后软件里边要有两个可执行文件,一个是软件本身,另一个更新程序然后数据库要有一张表写着最新的软件版本号,软件在启动的时候检查本地版本号和网上的是否一致,不一致的话就启动更新程序,关闭自己,然后通过更新程序来更新软件,更新结束之后再通过更新程序启动新软件 #region 更新方法 public void ProcUpdate() { updata ws = new updata(); label1.Text = "联系服务器,检测更新中......"; label1.Text = "联系服务器,检测更新中......"; this.Refresh(); System.Threading.Thread.Sleep(2000); label1.Text = "正在获取文件......"; IServer svli = getproxy.getpx(); DataTable dt = svli.GetVersion(); for (int i = 0; i < dt.Rows.Count; i++) { string filename = dt.Rows[i]["FileName"].ToString(); string Version = dt.Rows[i]["Version"].ToString(); string url = System.Configuration.ConfigurationSettings.AppSettings["url"].ToString(); RegistryKey r1 = Registry.CurrentUser; RegistryKey r2 = r1.OpenSubKey("QLSOFT", true); switch (filename) { case "clientdb.mdb": if (Version != clientdb) { ws.DownFile("http://" + url + "/Updates" + "/" + "clientdb.mdb", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("clientdb.mdb", Version); } break; case "Client.exe": if (Version != clientstr) { ws.DownFile("http://" + url + "/Updates" + "/" + "Client.exe", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("Client.exe", Version); } break; case "Client.exe.config": if (Version != configstr) { ws.DownFile("http://" + url + "/Updates" + "/" + "Client.exe.xml", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("Client.exe.config", Version); } break; } this.Refresh(); } }update.csusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.IO;using System.Net;using System.Diagnostics;using System.Threading;namespace Updates{ public class updata { public updata() { // // TODO: 在此处添加构造函数逻辑 // } //下载服务器文件 public void DownFile(string Url, System.Windows.Forms.ProgressBar pb) { HttpWebRequest qingqiu; HttpWebResponse xiangying; int IntStart = 0; int IntLen = 1024; int IntRead = 0; int intReaded = 0; int ContentLen = 0; byte[] Buf = new byte[IntLen - 1]; BinaryReader SR; BinaryWriter SW; FileStream S; //try //{ string Filename; string StrDir; //Url = Url.ToLower(); Url = Url.Replace("\\", "/"); Url = Url.Replace("//", "/"); Url = Url.Replace(":/", "://"); Filename = Url.Substring(Url.LastIndexOf(@"/") + 1); if (Filename == "clientdb.mdb") { Filename = Application.StartupPath + "\\Data\\clientdb.mdb"; } if (Filename == "Client.exe.config") { Filename = Application.StartupPath + "\\Client.exe.config"; } if (Filename == "Client.exe") { Filename = Application.StartupPath + "\\Client.exe"; } Filename = Filename.Replace("/", "\\"); Filename = Filename.Replace("\\\\", "\\"); StrDir = Filename.Substring(0, Filename.LastIndexOf("\\")); if (!(Directory.Exists(StrDir))) { Directory.CreateDirectory(StrDir); } qingqiu = (HttpWebRequest)HttpWebRequest.Create(Url); qingqiu.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)"; qingqiu.CookieContainer = new CookieContainer(); xiangying = (HttpWebResponse)qingqiu.GetResponse(); ContentLen = (int)xiangying.ContentLength; //MessageBox.Show(ContentLen.ToString()); //ContentLen=102400;// pb.Minimum = 0; pb.Maximum = (int)xiangying.ContentLength; S = new FileStream(Filename, FileMode.Create); SR = new BinaryReader(xiangying.GetResponseStream()); SW = new BinaryWriter(S); IntRead = SR.Read(Buf, 0, Buf.Length); while (IntRead > 0) { IntStart += IntRead; intReaded += IntRead; pb.Value = intReaded; SW.Write(Buf, 0, IntRead); IntRead = SR.Read(Buf, 0, Buf.Length); Application.DoEvents(); } SR.Close(); SW.Close(); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message + Url); //} } }}代码有删改,思路对吧,放到编辑器里改动一下就可以了 支持 另外网上有AutoUpdate的例子,你可以看看 http://www.cnblogs.com/glacier/archive/2009/03/27/1423542.html C#中的SHA1和MD5加密和PHP中相应算法结果为什么不同 如何正确应用范型返回值? picturebox如何设置自定义坐标 DataGridView中ReadOnly属性的问题 好书好多好多好书。。。 如何提取文本中的内容,并转化为指定格式的文件 c# 怎么判断 桌面 被点击 高分 求 Windows 服务 内存大小方法,注意,是Windows 服务 SQL ID递增问题 在winform中如果在datagrid中实现多重表头 如何设置数组中的各元素值不相同 不懂,这个正则表达式
我用vs2005 的ClickOnce 发布方法 可以自动更新!但是 就是没有卸载方式,,,,郁闷的我
帮忙解决下
然后软件里边要有两个可执行文件,一个是软件本身,另一个更新程序
然后数据库要有一张表写着最新的软件版本号,软件在启动的时候检查本地版本号和网上的是否一致,不一致的话就启动更新程序,关闭自己,然后通过更新程序来更新软件,更新结束之后再通过更新程序启动新软件
public void ProcUpdate()
{
updata ws = new updata();
label1.Text = "联系服务器,检测更新中......"; label1.Text = "联系服务器,检测更新中......";
this.Refresh();
System.Threading.Thread.Sleep(2000); label1.Text = "正在获取文件......"; IServer svli = getproxy.getpx();
DataTable dt = svli.GetVersion();
for (int i = 0; i < dt.Rows.Count; i++)
{
string filename = dt.Rows[i]["FileName"].ToString();
string Version = dt.Rows[i]["Version"].ToString(); string url = System.Configuration.ConfigurationSettings.AppSettings["url"].ToString(); RegistryKey r1 = Registry.CurrentUser;
RegistryKey r2 = r1.OpenSubKey("QLSOFT", true); switch (filename)
{
case "clientdb.mdb": if (Version != clientdb)
{
ws.DownFile("http://" + url + "/Updates" + "/" + "clientdb.mdb", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("clientdb.mdb", Version);
}
break;
case "Client.exe":
if (Version != clientstr)
{
ws.DownFile("http://" + url + "/Updates" + "/" + "Client.exe", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("Client.exe", Version);
}
break;
case "Client.exe.config":
if (Version != configstr)
{
ws.DownFile("http://" + url + "/Updates" + "/" + "Client.exe.xml", pb); //下载新的更新版本信息替换本地更新版本 IntFileCount = IntFileCount + 1; r2.SetValue("Client.exe.config", Version);
}
break;
}
this.Refresh();
}
}
update.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Threading;namespace Updates
{
public class updata
{
public updata()
{
//
// TODO: 在此处添加构造函数逻辑
//
} //下载服务器文件
public void DownFile(string Url, System.Windows.Forms.ProgressBar pb)
{
HttpWebRequest qingqiu;
HttpWebResponse xiangying;
int IntStart = 0;
int IntLen = 1024;
int IntRead = 0;
int intReaded = 0;
int ContentLen = 0;
byte[] Buf = new byte[IntLen - 1];
BinaryReader SR;
BinaryWriter SW;
FileStream S;
//try
//{
string Filename;
string StrDir;
//Url = Url.ToLower();
Url = Url.Replace("\\", "/");
Url = Url.Replace("//", "/");
Url = Url.Replace(":/", "://");
Filename = Url.Substring(Url.LastIndexOf(@"/") + 1); if (Filename == "clientdb.mdb")
{
Filename = Application.StartupPath + "\\Data\\clientdb.mdb"; }
if (Filename == "Client.exe.config")
{
Filename = Application.StartupPath + "\\Client.exe.config"; }
if (Filename == "Client.exe")
{
Filename = Application.StartupPath + "\\Client.exe"; }
Filename = Filename.Replace("/", "\\");
Filename = Filename.Replace("\\\\", "\\");
StrDir = Filename.Substring(0, Filename.LastIndexOf("\\"));
if (!(Directory.Exists(StrDir)))
{
Directory.CreateDirectory(StrDir);
}
qingqiu = (HttpWebRequest)HttpWebRequest.Create(Url);
qingqiu.UserAgent = @"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322)";
qingqiu.CookieContainer = new CookieContainer();
xiangying = (HttpWebResponse)qingqiu.GetResponse();
ContentLen = (int)xiangying.ContentLength;
//MessageBox.Show(ContentLen.ToString());
//ContentLen=102400;//
pb.Minimum = 0;
pb.Maximum = (int)xiangying.ContentLength;
S = new FileStream(Filename, FileMode.Create);
SR = new BinaryReader(xiangying.GetResponseStream());
SW = new BinaryWriter(S);
IntRead = SR.Read(Buf, 0, Buf.Length);
while (IntRead > 0)
{
IntStart += IntRead;
intReaded += IntRead;
pb.Value = intReaded;
SW.Write(Buf, 0, IntRead);
IntRead = SR.Read(Buf, 0, Buf.Length);
Application.DoEvents();
}
SR.Close();
SW.Close(); //}
//catch (Exception ex)
//{
// MessageBox.Show(ex.Message + Url);
//}
}
}
}
代码有删改,思路对吧,放到编辑器里改动一下就可以了
另外网上有AutoUpdate的例子,你可以看看