.Net Winform 程序自我重启 或删除自身

    技术2022-05-20  45

    Application.Restart();//自动重启

    下面是自动删除本身 没多做处理 很早以前写的测试用的

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { timer1.Start(); } [DllImport("kernel32.dll")] public static extern uint WinExec(string lpCmdLine, uint uCmdShow); private static void BeginKillSelf() { string vBatFile = Path.GetDirectoryName(Application.ExecutablePath) + "//a.bat"; using (StreamWriter vStreamWriter = new StreamWriter(vBatFile, false, Encoding.Default)) { vStreamWriter.Write(string.Format( ":del/r/n" + " del /"{0}/"/r/n" + "if exist /"{0}/" goto del/r/n" + "del %0/r/n", Application.ExecutablePath)); } WinExec(vBatFile, 0); } int b = 10;//初始只能执行10秒 private void timer1_Tick(object sender, EventArgs e) { b--; label1.Text = "剩余:" + b + "秒"; if (b == 0) { BeginKillSelf(); Application.Exit(); } } } }

     

     

     

    删除以后

     


    最新回复(0)