[DUG] Virus scanning causing GetFileVersion to go slow

Robo robo555 at gmail.com
Mon Sep 24 18:53:36 NZST 2012


Our program on start up checks for updates on a network drive by
comparing file version numbers against the local file.

The method runs quick on local files, but slow on the network file,
especially for files larger than 10MB. We found that disabling virus
scanning (Microsoft Forefront in this case) means the check is done in
less than 1sec instead of 10sec.

Anyone know a way to check the version number of a network file
without triggering the virus scanner? This is particularly problematic
because this runs every time the program starts, so start up time is
increasing by heaps.

Here's our code for checking file version:

function TFileVersion.ReadVersionInfo(sProgram: string; Major, Minor,
                                        Release, Build : pWord) :Boolean;
var
  Info:       PVSFixedFileInfo;
//{$ifdef VER120} {Delphi 4 definition for this differs from D2 & D3}
//  InfoSize:   Cardinal;
//{$else}
  InfoSize:   UINT;
//{$endif}
  nHwnd:      DWORD;
  BufferSize: DWORD;
  Buffer:     Pointer;
begin
  BufferSize := GetFileVersionInfoSize(pchar(sProgram),nHWnd); {Get buffer size}
  Result := True;
  if BufferSize <> 0 then begin {if zero, there is no version info}
    GetMem( Buffer, BufferSize); {allocate buffer memory}
    try
      if GetFileVersionInfo(PChar(sProgram),nHWnd,BufferSize,Buffer) then begin
        {got version info}
        if VerQueryValue(Buffer, '\', Pointer(Info), InfoSize) then begin
          {got root block version information}
          if Assigned(Major) then begin
            Major^ := HiWord(Info^.dwFileVersionMS); {extract major version}
          end;
          if Assigned(Minor) then begin
            Minor^ := LoWord(Info^.dwFileVersionMS); {extract minor version}
          end;
          if Assigned(Release) then begin
            Release^ := HiWord(Info^.dwFileVersionLS); {extract release version}
          end;
          if Assigned(Build) then begin
            Build^ := LoWord(Info^.dwFileVersionLS); {extract build version}
          end;

          iDateTime := (Info^.dwFileDateMS) shl 32;
          iDateTime := iDateTime + Info^.dwFileDateLS;
          //always comes back zero for some reason

        end else begin
          Result := False; {no root block version info}
        end;
      end else begin
        Result := False; {couldn't extract version info}
      end;
    finally
      FreeMem(Buffer, BufferSize); {release buffer memory}
    end;
  end else begin
    Result := False; {no version info at all in the file}
  end;
end;

Thanks

Robo


More information about the Delphi mailing list