在Windows上重命名正在运行的进程的文件映像 [英] Renaming A Running Process' File Image On Windows

查看:225
本文介绍了在Windows上重命名正在运行的进程的文件映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Vista SP1上有一个Windows服务应用程序,我发现用户正在重命名其可执行文件(正在运行时),然后重新启动,因此导致该文件无法在下次启动时启动,因为服务管理器无法再启动因为已重命名该文件,所以找到它.

I have a Windows service application on Vista SP1 and I've found that users are renaming its executable file (while it's running) and then rebooting, thus causing it to fail to start on next bootup because the service manager can no longer find the exe file since it's been renamed.

我似乎记得,在Windows的较早版本中,您无法执行此操作,因为操作系统在文件上设置了锁定.即使使用Vista SP1,我仍然无法在运行时复制现有文件-Windows报告该文件正在使用中-很有意义.那么为什么要允许我重命名呢?如果Windows需要从exe进入新的代码页,但是文件自启动以来已被重命名,会发生什么情况?我在重命名exe文件等时运行了Process Monitor,但是Process Mon并没有报告任何奇怪的情况,只是像其他文件一样记录了更改文件名的情况.

I seem to recall that with older versions of Windows you couldn't do this because the OS placed a lock on the file. Even with Vista SP1 I still cannot copy over the existing file when it's running - Windows reports that the file is in use - makes sense. So why should I be allowed to rename it? What happens if Windows needs to page in a new code page from the exe but the file has been renamed since it was started? I ran Process Monitor while renaming the exe file, etc, but Process Mon didn't report anything strange and just logged changing the filename like any other file.

有人知道幕后发生的事情吗? Windows允许更改正在运行的进程的文件名(或其依赖的DLL)似乎很不直观.我在这里想念什么?

Does anyone know what's going on here behind the scenes? It's seem counter intuitive that Windows would allow a running process' filename (or its dependent DLLs) to be changed. What am I missing here?

推荐答案

您的概念是错误的……文件名不是file-io Universe的中心……打开文件的句柄是.重命名文件时,文件不会移动到磁盘的其他部分,它仍位于同一位置,并且打开文件的内部数据结构的磁盘部分仍指向同一位置.最重要的是,您的观察是正确的.您可以重命名正在运行的程序而不会引起问题.重命名文件后,您就可以创建一个与正在运行的程序同名的新文件.如果您想在软件运行时更新软件,这实际上是有用的行为.

your concept is wrong ... the filename is not the center of the file-io universe ... the handle to the open file is. the file is not moved to a different section of disk when you rename it, it's still in the same place and the part of the disk the internal data structure for the open file is still pointing to the same place. bottom line is that your observations are correct. you can rename a running program without causing problems. you can create a new file with the same name as the running program once you've renamed it. this is actually useful behavior if you want to update software while the software is running.

这篇关于在Windows上重命名正在运行的进程的文件映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆