FormMain.cs
上传用户:lqb116
上传日期:2014-04-04
资源大小:2712k
文件大小:4k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- namespace LanMsgUpdate
- {
- /// <summary>
- /// Form1 的摘要说明。
- /// </summary>
- public class FormMain : System.Windows.Forms.Form
- {
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Label label1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public FormMain()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <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.groupBox1 = new System.Windows.Forms.GroupBox();
- this.label1 = new System.Windows.Forms.Label();
- this.groupBox1.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Location = new System.Drawing.Point(17, 11);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(256, 56);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "升级状态";
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(8, 24);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(232, 16);
- this.label1.TabIndex = 0;
- this.label1.Text = "正在安装升级包...";
- //
- // FormMain
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(290, 79);
- this.ControlBox = false;
- this.Controls.Add(this.groupBox1);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Name = "FormMain";
- this.Opacity = 0;
- this.ShowInTaskbar = false;
- this.Text = "LanMsg 智能更新程序";
- this.Load += new System.EventHandler(this.FormMain_Load);
- this.groupBox1.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.Run(new FormMain());
- }
- private void FormMain_Load(object sender, System.EventArgs e)
- {
- KillLanMsgProcess();//关闭所有正在运行的LanMsg进程
- DeCompress();//将新版本的LanMsg文件写入当前目录,并运行新版本的应用程序
- }
- private void KillLanMsgProcess()//关闭所有正在运行的LanMsg进程
- {
- System.Diagnostics.Process[] pTemp = System.Diagnostics.Process.GetProcesses();
- foreach(System.Diagnostics.Process pTempProcess in pTemp)
- if ((pTempProcess.ProcessName.ToLower() == ("LanMsg").ToLower()) || (pTempProcess.ProcessName.ToLower()) == ("LanMsg.exe").ToLower())
- pTempProcess.Kill();
- }
- private void DeCompress()//将资源文件写入当前目录
- {
- string TempFile=Application.StartupPath +"\LanMsg.exe";
-
- System.Threading.Thread.Sleep(10000);
- if(System.IO.File.Exists(TempFile))//删除当前目录低版本的 LanMsg
- System.IO.File.Delete(TempFile);
- byte[] b=new byte[1];
- if(!System.IO.File.Exists(TempFile))
- {
- System.IO.Stream tobjStream=System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("LanMsgUpdate.LanMsg.exe");
- System.IO.Stream f =new System.IO.FileStream(TempFile, System.IO.FileMode.CreateNew);
- long fLength=tobjStream.Length;
- for(int i=0;i<fLength;i++)
- {
- tobjStream.Read(b,0,1);
- f.WriteByte(b[0]) ;
- }
- f.Flush();
- f.Close();
- tobjStream.Close();
- System.Diagnostics.Process.Start(TempFile);//运行刚更新的应用程序
- }
- Application.Exit();
- }
-
- }
- }