FileVersionInfo.GetVersionInfo getting old version of an exe swapped at runtime
- by Richard
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 is set when the program is started to be the current version using the GetProductVersion(exe_name)
exe_name is set to be the name of the executable that is being updated.
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.