I am writing uninstaller.

Suppose it runs, deletes all files, and, ultimately, it must delete itself. But the process keeps the exe file. How to be?

    2 answers 2

    MoveFileEx() with the MOVEFILE_DELAY_UNTIL_REBOOT flag. Then your file will be deleted after a reboot. And it will not be necessary to dance with batch file.

    • And the decision on sharpe can throw? I'm also interested, usually treated with a batch file. - Monk
    • @Monk I can not, because I do not write on it. Calling this API on the network if the path to the file is known and without checking the result is one line. - Vladimir Martyanov
    • one
    • @Monk, you just need to do msi, then no batch files are needed;) - ixSci
    • @ixSci or NSIS. - αλεχολυτ

    Just in case, the option via CMD ( ping 127.0.0.1 -n 5 > nul command is needed for a delay of five seconds):

     Process.Start("cmd.exe", "/C ping 127.0.0.1 -n 5 > nul & del " + Application.ExecutablePath); Application.Exit(); 

    Also, as an option, you can create and run a simple bat-file - they can delete themselves without problems.