简体   繁体   English

重命名正在运行的应用程序 - 危险吗?

[英]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使用 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).这不是可执行文件或 dll 经常发生的事情,尽管您应该了解可能进行一些自我认证(许可证检查)的嵌入式资源和程序。 It's usually best to restart the corresponding application sooner than rather later, much like windows will urge you to reboot on system updates通常最好尽早重启相应的应用程序,就像 windows 会敦促您在系统更新时重启

Renaming an.exe is usually possible without any problems - renaming.dll's is quite another story.重命名 an.exe 通常没有任何问题 - 重命名.dll 是另一回事。

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 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轻松切换 DLL 等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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