Digging version info out of WindowsTerminal.exe? #12576

Closed
opened 2026-01-31 03:19:13 +00:00 by claunia · 4 comments
Owner

Originally created by @vefatica on GitHub (Feb 14, 2021).

Following examples from the online help, I'm using this code.

struct LANGANDCODEPAGE
{
	WORD wLanguage;
	WORD wCodePage;
} *lpTranslate;

WCHAR szFileName[] = L"v:\\wtpreview\\exe\\WindowsTerminal.exe";
DWORD	dwHandle, dwBufSize = GetFileVersionInfoSizeW(szFileName, &dwHandle);
LPVOID Buf = malloc(dwBufSize);
BOOL b = GetFileVersionInfoW(szFileName, 0, dwBufSize, Buf);
wprintf(L"GetFileVersionInfoW returned %s\n", b ? L"TRUE" : L"FALSE");
UINT uDataSize;
b = VerQueryValue(Buf, L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &uDataSize);
wprintf(L"VerQueryValue returned %s\n", b ? L"TRUE" : L"FALSE");
if ( b == TRUE )
{
	wprintf(L"VerQueryValue gave %u bytes of data\nwLanguage = %04x\nwCodePage = %04x\n", uDataSize, lpTranslate[0].wLanguage, lpTranslate[0].wCodePage);
}

It produces this.

GetFileVersionInfoW returned TRUE
VerQueryValue returned TRUE
VerQueryValue gave 4 bytes of data
wLanguage = 0000
wCodePage = 04b0

That would seem to be wrong because (1) looking at the raw data (in Buf), and (2) looking at the Version resource with devenv, I see the string "040904b0".

The same code successfully gets wLanguage = 0409 out of the few other EXEs that I've tried.

And if I subsequently try to get "ProductVersion" like this

wsprintf(szQuery, L"\\StringFileInfo\\%04x%04x\\ProductVersion", lpTranslate[i].wLanguage, lpTranslate[i].wCodePage);
wprintf(L"Using query string: %s\n", szQuery);
b = VerQueryValueW(Buf, szQuery, &pVoid, &dwQueryDataSize);

It fails (GLE = 1813 (resource can't be found)). It succeeds if I use L"\StringFileInfo\040904b0\ProductVersion" giving me the string "1.6.210210002-release1.6".

Any ideas? Thanks!

Originally created by @vefatica on GitHub (Feb 14, 2021). Following examples from the online help, I'm using this code. ``` struct LANGANDCODEPAGE { WORD wLanguage; WORD wCodePage; } *lpTranslate; WCHAR szFileName[] = L"v:\\wtpreview\\exe\\WindowsTerminal.exe"; DWORD dwHandle, dwBufSize = GetFileVersionInfoSizeW(szFileName, &dwHandle); LPVOID Buf = malloc(dwBufSize); BOOL b = GetFileVersionInfoW(szFileName, 0, dwBufSize, Buf); wprintf(L"GetFileVersionInfoW returned %s\n", b ? L"TRUE" : L"FALSE"); UINT uDataSize; b = VerQueryValue(Buf, L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &uDataSize); wprintf(L"VerQueryValue returned %s\n", b ? L"TRUE" : L"FALSE"); if ( b == TRUE ) { wprintf(L"VerQueryValue gave %u bytes of data\nwLanguage = %04x\nwCodePage = %04x\n", uDataSize, lpTranslate[0].wLanguage, lpTranslate[0].wCodePage); } ``` It produces this. ``` GetFileVersionInfoW returned TRUE VerQueryValue returned TRUE VerQueryValue gave 4 bytes of data wLanguage = 0000 wCodePage = 04b0 ``` That would seem to be wrong because (1) looking at the raw data (in Buf), and (2) looking at the Version resource with devenv, I see the string "040904b0". The same code successfully gets wLanguage = 0409 out of the few other EXEs that I've tried. And if I subsequently try to get "ProductVersion" like this ``` wsprintf(szQuery, L"\\StringFileInfo\\%04x%04x\\ProductVersion", lpTranslate[i].wLanguage, lpTranslate[i].wCodePage); wprintf(L"Using query string: %s\n", szQuery); b = VerQueryValueW(Buf, szQuery, &pVoid, &dwQueryDataSize); ``` It fails (GLE = 1813 (resource can't be found)). It succeeds if I use L"\\StringFileInfo\\040904b0\\ProductVersion" giving me the string "1.6.210210002-release1.6". Any ideas? Thanks!
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 03:19:13 +00:00
Author
Owner

@DHowett commented on GitHub (Feb 14, 2021):

Check out the code here: https://github.com/microsoft/terminal/blob/main/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp#L921

There is something in our build system that produces the wrong version locale info, but because this is not an API contract we haven’t cared to fix it.

@DHowett commented on GitHub (Feb 14, 2021): Check out the code here: https://github.com/microsoft/terminal/blob/main/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp#L921 There is something in our build system that produces the wrong version locale info, but because this is not an API contract we haven’t cared to fix it.
Author
Owner

@vefatica commented on GitHub (Feb 14, 2021):

Thanks. I'll look later. What's an "API contract"?

@vefatica commented on GitHub (Feb 14, 2021): Thanks. I'll look later. What's an "API contract"?
Author
Owner

@DHowett commented on GitHub (Feb 14, 2021):

That is to say, “if we break it or change it we never offered you specific support to begin with.” 😄

@DHowett commented on GitHub (Feb 14, 2021): That is to say, “if we break it or change it we never offered you specific support to begin with.” 😄
Author
Owner

@vefatica commented on GitHub (Feb 15, 2021):

I still don't understand. Let's drop it.

@vefatica commented on GitHub (Feb 15, 2021): I still don't understand. Let's drop it.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12576