Question about self-renewal

I looked at a simple mechanism for self-updating executable files. (I cannot use Click-Once due to the nature of the application - trust me on this)

I noticed that the in-flight assembly may move to another location on the disk, apparently because the executing assembly is actually a copy in memory) and that the original location of the file may be overwritten. This is confirmed by the following fragment of the evidence concept ...

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"); 

In my XP development system, this leads to the build file being moved to c:\ANewExe.exe , and the original location of the file is filled with the text "some text".

I think my question is whether this is a safe and / or reliable method for use in different versions of Windows with XP), or are there other ways to achieve this functionality? Will this be detected as a possible behavior of viruses using AV systems, to which I do not have access for testing?

TIA

+4
source share
1 answer

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

Is the nature of the application such that it MUST remain operational? It seems much easier to have an update to download a new EXE, overwrite it, and then invite to restart the application.

+6
source

Source: https://habr.com/ru/post/1301840/


All Articles