My Notebook

A platform independent way for a C# program to update itself

Author
Andreas Rohner
Date

In Windows you cannot write to an executable file while it is still running, because the file is locked by the file system. Therefore a running application can never delete or update itself without the help of another process that does the actual work. However, this rule doesn't apply to Batch-scripts. They are interpreted line by line by cmd.exe and can delete themselves. This post demonstrates a simple trick how you can use this fact to generate a temporary self-removing Batch-script in C# to update your application. read more...