How can I make my .NET application erase itself?

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

    You will never be able to guarantee that this will work, as long as you require a physical presence on the machine. For example:

    • What if the app fails to release a resource in a timely fashion while you're trying to delete it? An error occurs, and the app remains.
    • The behavior of one app starting another which then deletes the first app is very suspicious from an AV perspective. You are likely to trigger defenses on a user's machine which may kill the process that's trying to kill your original app.
    • If you do something like delete a file at reboot, what if the user moves your file in between or makes a copy? It's not in the original spot anymore, and the app remains.

    If your application requires this level of security, consider hosting it on a machine you control (e.g., by providing a web service and letting a stub client access it that way).

    On a somewhat related note, one is also tempted to speculate about the motives of someone who (1) requires a physical presence on someone's machine and (2) wants to delete the evidence that the app existed.

提交回复
热议问题