How can I make my .NET application erase itself?

前端 未结 11 665
梦如初夏
梦如初夏 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:15

    Since my application (a Windows Service) is installed via the Windows Installer, I self-delete using this:

    Dim uninstall_params As String = "/x {MY-PRODUCTS-GUID} /qn /norestart REBOOT=ReallySuppress"
    proc.StartInfo = New ProcessStartInfo("msiexec.exe", uninstall_params)
    proc.Start()
    Environment.Exit(-1)
    

    Sorry--it's in VB, but it should be easily convertible to C#.

提交回复
热议问题