Search code examples
c#.netversionwindows-terminal

Get Version of the Windows Terminal (wt.exe)


Background

One can obtain the Windows Terminal's version by running the command wt -v, which results in a message box being displayed as such:

Question

Is it possible to obtain this version string programmatically using (preferrably) a .NET language such as C#? (solutions using C/C++ are also acceptable for my scenario).


Solution

  • For now, I am currently resolving the issue as follows (thanks to Andrew Morton and Sinatr for their comments):

    1. Check for the existence of the registry key HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\wt.exe
    2. If present, obtain the path stored in the string value (Default). This is usually something along the lines of C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.21.3231.0_x64__8wekyb3d8bbwe\wt.exe.
    3. Should the previous method fail, the path of the Windows Terminal will instead be extracted by looking for an instance of wt.exe or WindowsTerminal.exe inside of the current process tree. (Results are only included if the executable resides in a sub-directory of %ProgramFiles%\WindowsApps to avoid false positives.)
    4. Once a valid path has been obtained, the version is exctracted using the following code:
      string version_string = FileVersionInfo.GetVersionInfo(path).FileVersion;
      
    5. Should the previous method be unsuccessful, the version will instead be extracted from the path using Regex (the expression is (\d+\.){3}\d+).
    6. The obtained version string is then converted to an instance of Version using Version.TryParse.

    I am not happy with that solution and I'd be glad to accept a more 'official' way to extract the version number, but this works for me at the moment.