简体   繁体   中英

rename a running application - dangerous?

I'm writing a small utility to update our application.

In order to update the update utility, I would like it to rename itself while running and copy the new version from a remote source. So the next time you start the updater, you have a new version.

Do you know of any possible problems which could occur, using that mechanismn?

Actually I was surprised it is at all possible to rename a running program (lost a cake there...), while deleting is not allowed.

Kind regards for any hints

using Win XP, .NET 3.5

You can rename - because it alters metadata only, but the actual file allocation chain is unmodified, which means they can stay memory-mapped in the process(es) that use it.

This is an ubiquitous trick in installers, when they have to upgrade 'live' running binaries.

It can cause trouble if the application tries to later reopen from the original filespecification. This is not something that regularly happens with executables or dlls, though you should be aware of embedded resources and programs that may do some self-certification (license checks). It's usually best to restart the corresponding application sooner than rather later, much like windows will urge you to reboot on system updates

Renaming an.exe is usually possible without any problems - renaming.dll's is quite another story.

I'd suggest using subdirectories instead (labeled with the date or version number) and creating a small launcher application (with the same name and icon as your "real" application) that reads the current version from a text file and launches it.

ie

updater.exe (the launcher)
updater.config (containing /updater_v_02/updater.exe)
 /updater_v_01/updater.exe (the real app, v 01)
 /updater_v_02/updater.exe (the real app, v 02)

This way, you can

  • keep several versions of your application around
  • test a new version (by directly launching it from the subdir) while your users continue using the old version
  • switch DLLs etc. without any hassle

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