开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜