FileVersionInfo.GetVersionInfo gets an old version of exe replaced at runtime

I have a program running in C # that sometimes updates while it runs by replacing exe with a new one. I want the program to regularly check if it has been updated, and if so, restart it. For this, I use the following function.

    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 starts as the current version using GetProductVersion (exe_name)

exe_name is set as the name of the executable that is being updated.

, MainProgram.exe ( , ), GetProductVersion - , , ! . Windows Vista .Net 3.5.

+3
2

? Windows, , .exe, - Windows. , .NET, , , , .

EDIT: , Windows , , . Vista, , - , , Windows Windows . - , . (MSIEXEC) , . , Windows C:\Program Files\whatever, % USERPROFILE%\AppData\Local\VirtualStore\Program Files\ , . , "" , , , "" . , , .

+1

, - .

restart.txt , ?

+1

Source: https://habr.com/ru/post/1749928/


All Articles