简体   繁体   中英

Self updating application question

I've been looking at a simple machanism for self-updating executable files. (I can't use Click-Once due to the nature of the application - trust me on this)

I've noticed that an in-flight assembly can move itself to another location on disk, presumably because the executing assembly is actually an in-memory copy), and that the original location of the file can be overwritten. This is proven with the following proof-of-concept snippet...

string assemblyStart = System.Reflection.Assembly.GetExecutingAssembly().Location;
Console.WriteLine(assemblyStart);

if(File.Exists(@"C:\ANewExe.exe")) 
{
    File.Delete(@"C:\ANewExe.exe");
}
File.Move(assemblyStart,@"C:\ANewExe.exe");
string assemblyMoved = System.Reflection.Assembly.GetExecutingAssembly().Location;
Console.WriteLine(assemblyMoved);  // still reports as the original location

File.WriteAllText(assemblyStart,"some text");

On my XP development system, this results in the assembly file being moved to c:\\ANewExe.exe , and the original file location being filled with the text "some text".

I guess my question here is, is this a safe and/or reliable method to use across versions of Windows from XP up), or are there other ways to achieve this functionality? Will this be detected as possible virus behaviour by AV systems that I don't have access to to test?

TIA

Notepad++ uses GUP - http://gup-w32.sourceforge.net/ . Worth a look.

Is the nature of the application such that it MUST stay running? It seems far easier to have an updater download a new EXE, overwrite the current one, and then prompt to restart the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM