Getting the resource info you want

by Michael S. Kaplan, published on 2007/02/22 03:31 -05:00, original URI:

Developer Eric asked on one of the internal aliases:

The following code fragment to query the original filename of notepad.exe will set pValue to “NOTEPAD.EXE.MUI” on Vista. Is this expected? I’m apparently getting the original file name of the language resources. I was expecting to get “NOTEPAD.EXE”. Is this the standard for all MUI apps, or could some be built to return “APP.EXE” and others “APP.EXE.MUI” ?

dwSize= GetFileVersionInfoSize( “C:\\windows\\system32\\notepad.exe”, &dwHandle);
buf= malloc( dwSize);
GetFileVersionInfo( sPath, dwHandle, dwSize, buf);
VerQueryValue( buf, L"\\StringFileInfo\\040904b0\\OriginalFilename", (LPVOID*)&pValue, &uLen);

Thanks for any info.

To be honest I had no idea, but I forwarded it to the MUI dev team, and Sunggook knew the answer:

Yes, it is expected behavior on Vista with MUI’ized files.

The default behavior of GetFileVersionInfo return merged info of LN and MUI file. Fixed information from LN and variable from MUI. 

If you want to see LN file name like Notepad.exe, please use GetFileVersionInfoEx(FILE_VER_GET_NEUTRAL..).

And that does look to be the trick -- GetFileVersionInfoSizeEx/GetFileVersionInfoEx rather than GetFileVersionInfoSize/GetFileVersionInfo, using the appropriate flag to specify whether you want the language neutral resources or the localized ones....

Please note that GetFileVersionInfoSizeEx and GetFileVersionInfoEx are new for Vista and they only have Unicode versions, something that you will see more and more of as the team I am on communicates the need for this approach going forward, this way rather than this other way. :-)


This post brought to you by  (U+a130, a.k.a. YI SYALLABLE TUT)

# Miral on 25 Feb 2007 6:52 PM:

I hope there's a backwards compatibility layer where it'll give you the old answer if you don't have a Vista manifest or something.  Otherwise you could break things.  Not that too many things should be relying on the OriginalFilename, but I've seen it happen.

# Michael S. Kaplan on 25 Feb 2007 8:55 PM:

I do not know of one, myself. Though I imagine the same problem exists any time the file list changes in an OS version, and it is not like there can be a backcompat layer for every file....

# Lewis Balentine on 18 Jun 2008 9:18 PM:

unfortunately the constants "FILE_VER_GET_NEUTRAL" and "FILE_VER_GET_LOCALISED" are undefined in the MSDN library.  As the function REQUIRES a parameter for dwFlags and there if not information on what those parameters should be the function is totally useless.


If you do not believe me ... try searching for one of them.

# Michael S. Kaplan on 18 Jun 2008 10:58 PM:

From verrsrc.h in the Platform SDK:

   FILE_VER_GET_... flags are for use by 

#define FILE_VER_GET_NEUTRAL    0x02

# on 26 Aug 2008 10:41 AM:

"random stuff of dubious value"...but if you can make head and tail when you read it, you know a lot I don't !

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day