Self deletable application in C# in one executable

前端 未结 7 1811
北荒
北荒 2020-11-30 23:26

Is it possible to make an application in C# that will be able to delete itself in some condition.

I need to write an updater for my application but I don\'t want the

7条回答
  •  攒了一身酷
    2020-11-30 23:54

    public void uninstall() {
        string app_name = Application.StartupPath + "\\" + Application.ProductName + ".exe";
        string bat_name = app_name + ".bat";
    
        string bat = "@echo off\n"
            + ":loop\n"
            + "del \"" + app_name + "\"\n"
            + "if Exist \"" + app_name + "\" GOTO loop\n"
            + "del %0";
    
        StreamWriter file = new StreamWriter(bat_name);
        file.Write(bat);
        file.Close();
    
        Process bat_call = new Process();
        bat_call.StartInfo.FileName = bat_name;
        bat_call.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        bat_call.StartInfo.UseShellExecute = true;
        bat_call.Start();
    
        Application.Exit();
    }
    

    self delete by an external executable file ".bat" for windows form applications.

提交回复
热议问题