CodedK
asked on
Get File version info.
Hi.
I need a small working code to retrieve some version information for a file.
I've searched EE database and saw some answers but the code is big and some times doesnt work.
Thanks in advance :)
I need a small working code to retrieve some version information for a file.
I've searched EE database and saw some answers but the code is big and some times doesnt work.
Thanks in advance :)
ASKER
Hi jpedef, thanks.
There is a problem with the code...
It shows 'no version info available' for files that have a version string.
I use it like this :
GetFileVersionString(Path of exe + exefilename)
How can i get the other strings like "comments","FileDescriptio n","Compan y" etc ?
There is a problem with the code...
It shows 'no version info available' for files that have a version string.
I use it like this :
GetFileVersionString(Path of exe + exefilename)
How can i get the other strings like "comments","FileDescriptio
Try this one:
function getVersion : string; // poached from the online documentation
const NOVIDATA = '';
var
dwInfoSize, // Size of VERSIONINFO structure
dwVerSize, // Size of Version Info Data
dwWnd: DWORD; // Handle for the size call.
FI: PVSFixedFileInfo; // Delphi structure; see WINDOWS.PAS
ptrVerBuf: Pointer; // pointer to a version buffer
strFileName, // Name of the file to check
strVersion : string; // Holds parsed version number
begin
strFileName := paramStr( 0 );
dwInfoSize := getFileVersionInfoSize( pChar( strFileName ), dwWnd);
if ( dwInfoSize = 0 ) then
result := NOVIDATA
else
begin
getMem( ptrVerBuf, dwInfoSize );
try
if getFileVersionInfo(pChar(s trFileName ),dwWnd,dw InfoSize,p trVerBuf) and verQueryValue(ptrVerBuf,'\ ',pointer( FI),dwVerS ize) then
strVersion := format('%d.%d.%d.%d',[hiWo rd(FI.dwFi leVersionM S),loWord( FI.dwFileV ersionMS),
hiWord(FI.dwFileVersionLS) ,loWord(FI .dwFileVer sionLS)]);
finally
freeMem( ptrVerBuf );
end;
end;
Result := strVersion;
end;
function getVersion : string; // poached from the online documentation
const NOVIDATA = '';
var
dwInfoSize, // Size of VERSIONINFO structure
dwVerSize, // Size of Version Info Data
dwWnd: DWORD; // Handle for the size call.
FI: PVSFixedFileInfo; // Delphi structure; see WINDOWS.PAS
ptrVerBuf: Pointer; // pointer to a version buffer
strFileName, // Name of the file to check
strVersion : string; // Holds parsed version number
begin
strFileName := paramStr( 0 );
dwInfoSize := getFileVersionInfoSize( pChar( strFileName ), dwWnd);
if ( dwInfoSize = 0 ) then
result := NOVIDATA
else
begin
getMem( ptrVerBuf, dwInfoSize );
try
if getFileVersionInfo(pChar(s
strVersion := format('%d.%d.%d.%d',[hiWo
hiWord(FI.dwFileVersionLS)
finally
freeMem( ptrVerBuf );
end;
end;
Result := strVersion;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Russell :)
No problem
Russell
Russell
const
InfoNum = 10;
InfoStr: array[1..InfoNum] of string = ('CompanyName',
'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright',
'LegalTradeMarks', 'OriginalFileName', 'ProductName', 'ProductVersion', 'Comments');
function GetFileVersionString(AFile
var
VerStr: string;
n, Len: DWORD;
Buf: PChar;
Value: PChar;
begin
n := GetFileVersionInfoSize(PCh
if n > 0 then
begin
Buf := AllocMem(n);
try
GetFileVersionInfo(PChar(A
if VerQueryValue(Buf, PChar('\StringFileInfo\040
VerStr := 'Version: ' + Value
else
VerStr := 'Unknown version ';
finally
FreeMem(Buf);
end;
end
else
VerStr := 'No version information available';
Result := VerStr;
end;