FileVersionInfo.GetVersionInfo变老版本的EXE文件在运行时交换 [英] FileVersionInfo.GetVersionInfo getting old version of an exe swapped at runtime

查看:282
本文介绍了FileVersionInfo.GetVersionInfo变老版本的EXE文件在运行时交换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c#执行程序是通过交换该exe到一个新的运行时有时更新。我希望该计划,并定期检查它是否已被更新,如果是这样,重新启动。我用下面的函数来做到这一点。

I have a program executing in c# that is sometimes updated while it is running by swapping the exe to a new one. I want the program to routinely check if it has been updated and if so, restart. I use the following function to do this.

    public static bool DoINeedToRestart(string exe_name)
    {

        Version cur_version = new Version(MainProgram.StartVersion);
        Version file_version = new Version(GetProductVersion(exe_name));
        MessageBox.Show("Comparing cur_version " + cur_version.ToString() + " with " + file_version.ToString());
        if (file_version > cur_version)
        {
            return true;
        }
        return false;
    }

    public static string GetProductVersion(string path_name)
    {
            FileVersionInfo myFI = FileVersionInfo.GetVersionInfo(path_name);
            return myFI.FileVersion;
    }



当程序开始使用为当前版本MainProgram.StartVersion设置所述GetProductVersion(exe_name)

MainProgram.StartVersion is set when the program is started to be the current version using the GetProductVersion(exe_name)

exe_name被设定为正在更新的可执行文件的名称。

exe_name is set to be the name of the executable that is being updated.

我有一次在MainProgram.exe文件已被更新的问题仍然(我通过查看文件属性并检查文件版本手动验证这一点),在GetProductVersion返回旧文件的版本,我不知道为什么!任何帮助是极大的赞赏。我运行Windows Vista与.net 3.5。

The problem I have is once the MainProgram.exe file has been updated (I verify this manually by looking at the file properties and checking the file version), the GetProductVersion still returns the old file version and I have no idea why! Any help is greatly appreciated. I'm running Windows Vista with .Net 3.5.

推荐答案

什么操作系统?如果这是Windows的话,只怕你是错误的交换对正在执行一个.exe文件 - 所有正在运行的程序在Windows内核的虚拟内存管理器锁定。这是完全可能的,你有一些.NET库做重定向幕后,使它看起来好像新的文件是在地方,但只有文件通过该库将受影响的访问。

What operating system? If this is Windows, then I'm afraid you're mistaken about swapping a .exe file that's executing -- all running programs are locked by the virtual memory manager in the Windows kernel. It's entirely possible that you have some .NET library doing redirection behind the scenes to make it look as if the new file is in place, but only file access through that library will be affected.

编辑:据我所知,视窗抗拒尝试删除或重命名,不仅是映射到内存可执行文件,而且所有的父目录。既然你在Vista上,它实际上是有可能你看到一个正面的影响 - 对于非管理员程序时,Windows写入重定向和后来的Windows和程序文件目录读取到每个用户的虚拟区域。如果您通过任何非高架方式启动程序,你实际上可能正在运行的应用程序在虚拟区域的副本。安装程序服务(MSIEXEC)具有完全提升的管理员权限运行,所以它是免疫的重定向。所以我断定,Windows安装程序将覆盖在C版本:\Program Files\whatever,而你的应用程序从%USERPROFILE%\AppData\Local\VirtualStore\Program Files\whatever叠加,看到的版本,是不变的。一般来说,如果在真实的目录的变化的版本,它将有一个较新的修改时间大于覆盖版本,因此,真实的版本将被使用。但是,如果安装过程保留修改时间,那么它有可能覆盖具有更近的时间,并继续使用。

As far as I know, Windows resists attempts to delete or rename not only the executable which is mapped into memory, but also all parent directories. Since you're on Vista, it is actually possible you are seeing the effects of a façade -- for non-administrator programs, Windows redirects writes and later reads of the Windows and Program Files directories into a per-user virtual area. If you're starting the program through any non-elevated means, you might actually be running a copy of the app in the virtual area. The Installer service (MSIEXEC) runs with fully-elevated admin rights, so it is immune to the redirection. So I posit that Windows Installer overwrites the version in C:\Program Files\whatever, while your app sees the version from the %USERPROFILE%\AppData\Local\VirtualStore\Program Files\whatever overlay, which is unchanged. Normally if the version in the "real" directory changes, it will have a newer modification time than the overlay version, so the "real" version would be used. But if the install process is preserving the modification time, then it is possible that the overlay has the more recent time and continues to be used.

这篇关于FileVersionInfo.GetVersionInfo变老版本的EXE文件在运行时交换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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