c# getting file version of a swapped exe at runtime
Posted
by Richard
on Stack Overflow
See other posts from Stack Overflow
or by Richard
Published on 2010-06-14T12:59:44Z
Indexed on
2010/06/14
13:02 UTC
Read the original article
Hit count: 110
c#
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;
}
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.
© Stack Overflow or respective owner