读书人

C# 软件晋级程序制作

发布时间: 2011-12-19 23:23:36 作者: rapoo

C# 软件升级程序制作
如果做完一个软件后,要进行更新的话,要如何升级程序??

[解决办法]
mark
以下是我写的程序很垃圾,参考一下吧。


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using TextAndIni.Ini;
using TextAndIni.Text;
using System.Net;
using System.IO;
using System.Text;
using System.Threading ;
using System.Runtime.InteropServices;
namespace 更新程序
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
[DllImport( "user32.dll ")]
private static extern unsafe IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport( "User32.dll ")]
private static extern unsafe int SendMessage(IntPtr hWnd, int Msg,IntPtr wParam,string lParam );
private const int WM_CLOSE = 0x10; //关闭程序。
private string windowName; //主程序窗口名称。
private ArrayList FileList1; //现有文件列表。
private ArrayList FileList2; //下载到的文件列表。
private ArrayList FileSize; //文件大小。
private ArrayList UpdataList; //要更新的文件列表。
private string Hurl; //下载的网址。
private IntPtr Hwnd; //窗口句柄。
private Thread th; //进程1。
private Thread thread; //进程2。
private MyText Textlog;
//*******************************************************************************************
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.StatusBar statusBar1;
private System.ComponentModel.IContainer components;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
windowName= " ";
string data = string.Format( "{0}年{1}月{2}日 ",DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day);
Textlog = new MyText(Application.StartupPath+ "\\log\\ "+data+ ".log ");
Textlog.WriteText( "**************************************************************************\r\n ");
Textlog.WriteText( "日期: "+DateTime.Now.ToString()+ "程序启动\r\n ");
Textlog.WriteText( "**************************************************************************\r\n ");

}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.listView1 = new System.Windows.Forms.ListView();
this.label1 = new System.Windows.Forms.Label();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//


// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(24, 232);
this.progressBar1.Name = "progressBar1 ";
this.progressBar1.Size = new System.Drawing.Size(336, 16);
this.progressBar1.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.listView1);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1 ";
this.groupBox1.Size = new System.Drawing.Size(376, 176);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "测试服务器状态 ";
//
// listView1
//
this.listView1.Location = new System.Drawing.Point(8, 24);
this.listView1.Name = "listView1 ";
this.listView1.Size = new System.Drawing.Size(360, 144);
this.listView1.TabIndex = 0;
this.listView1.View = System.Windows.Forms.View.Details;
//
// label1
//
this.label1.Location = new System.Drawing.Point(32, 200);
this.label1.Name = "label1 ";
this.label1.Size = new System.Drawing.Size(328, 24);
this.label1.TabIndex = 4;
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// statusBar1
//
this.statusBar1.Location = new System.Drawing.Point(0, 261);
this.statusBar1.Name = "statusBar1 ";
this.statusBar1.Size = new System.Drawing.Size(392, 16);
this.statusBar1.TabIndex = 5;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(392, 277);
this.Controls.Add(this.statusBar1);
this.Controls.Add(this.label1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.progressBar1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "Form1 ";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "万博软件更新程序 ";
this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing);
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>

[解决办法]
用Application Updater Block生成一个自我更新的WinForms 应用(amart client)
http://blog.csdn.net/yls087412/archive/2007/01/16/1484233.aspx

下载地址
http://www.microsoft.com/downloads/details.aspx?FamilyId=C6C09314-E222-4AF2-9395-1E0BD7060786&displaylang=en

读书人网 >C#

热点推荐