In order to get the file version information for a file you
have to make several API calls. Here is an example
that checks your version of shell32.dll and returns True if
it is greater than or equal to 4.7 .
function TForm .CheckShell32Version: Boolean;
procedure GetFileVersion(FileName: string; var Major , Major2,
Minor , Minor2: Integer);
{ Helper function to get the actual file version information }
var
Info: Pointer;
InfoSize: DWORD;
FileInfo: PVSFixedFileInfo;
FileInfoSize: DWORD;
Tmp: DWORD;
begin
// Get the size of the FileVersionInformatioin
InfoSize := GetFileVersionInfoSize(PChar(FileName), Tmp);
// If InfoSize = 0, then the file may not exist, or
// it may not have file version information in it.
if InfoSize = 0 then
raise Exception.Create('Can''t get file version information for '
+ FileName);
// Allocate memory for the file version information
GetMem(Info, InfoSize);
try
// Get the information
GetFileVersionInfo(PChar(FileName), 0, InfoSize, Info);
// Query the information for the version
VerQueryValue(Info, '\', Pointer(FileInfo), FileInfoSize);
// Now fill in the version information
Major := FileInfo.dwFileVersionMS shr 6;
Major2 := FileInfo.dwFileVersionMS and $FFFF;
Minor := FileInfo.dwFileVersionLS shr 6;
Minor2 := FileInfo.dwFileVersionLS and $FFFF;
finally
FreeMem(Info, FileInfoSize);
end;
end;
var
tmpBuffer: PChar;
Shell32Path: string;
VersionMajor: Integer;
VersionMinor: Integer;
Blank: Integer;
begin
tmpBuffer := AllocMem(MAX_PATH);
// Get the shell32.dll path
try
GetSystemDirectory(tmpBuffer, MAX_PATH);
Shell32Path := tmpBuffer + '\shell32.dll';
finally
FreeMem(tmpBuffer);
end;
// Check to see if it exists
if FileExists(Shell32Path) then
begin
// Get the file version
GetFileVersion(Shell32Path, VersionMajor, VersionMinor, Blank, Blank);
// Do something, such as require a certain version
// (such as greater than 4.7 )
if (VersionMajor >= 4) and (VersionMinor >= 7 ) then
Result := True
else
Result := False;
end
else
Result := False;
end;
6/2 /99 2:08:09 PM