How can I make my .NET application erase itself?

前端 未结 11 709
梦如初夏
梦如初夏 2020-12-08 10:37

How can I make my C# app erase itself (self-destruct)? Here\'s two ways that I think might work:

  • Supply another program that deletes the main program. How is t
11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 11:17

    sorted by NJ c# the other codes does not work so its simple if u create bath file that loops to del application and the batch file itself u can use takkill command to kill the process if u dont want to use application.close method

            `string delname = "test.cmd";
            string fileurl = Application.ExecutablePath;
            System.IO.StreamWriter file = new System.IO.StreamWriter(delname);
            file.WriteLine(":Repeat");
            file.WriteLine("del \"" + fileurl + "\"");
            file.WriteLine("if exist \"" + fileurl + "\" goto Repeat");
            file.WriteLine("del \"" + delname + "\"");
            file.Close();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.FileName = delname;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            Process.Start(startInfo);`
    

    ` Th3 3e3 one is not 3d parts ov one I5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

提交回复
热议问题