MsiGetFileHash Function

Windows Installer

MsiGetFileHash Function

The MsiGetFileHash function takes the path to a file and returns a 128-bit hash of that file. Authoring tools may use MsiGetFileHash to obtain the file hash needed to populate the MsiFileHash table.

Windows Installer uses file hashing as a means to detect and eliminate unnecessary file copying. A file hash stored in the MsiFileHash table may be compared to a hash of an existing file on the user's computer.

Syntax

C++UINT MsiGetFileHash(
  __in   LPCTSTR szFilePath,
  __in   DWORD dwOptions,
  __out  PMSIFILEHASHINFO pHash
);

Parameters

szFilePath [in]

Path to file that is to be hashed.

dwOptions [in]

The value in this column must be 0. This parameter is reserved for future use.

pHash [out]

Pointer to the returned file hash information.

Return Value

Value Meaning
ERROR_SUCCESS

The function completed successfully.

ERROR_FILE_NOT_FOUND

The file does not exist.

ERROR_ACCESS_DENIED

The file could not be opened to get version information.

E_FAIL

Unexpected error has occurred.

 

Remarks

The entire 128-bit file hash is returned as four 32-bit fields. The numbering of the four fields is zero-based. The values returned by MsiGetFileHash correspond to the four fields of the MSIFILEHASHINFO structure. The first field corresponds to the HashPart1 column of the MsiFileHash table, the second field corresponds to the HashPart2 column, the third field corresponds to the HashPart3 column, and the fourth field corresponds to the HashPart4 column.

The hash information entered into the MsiFileHash table must be obtained by calling MsiGetFileHash or the FileHash method. Do not attempt to use other methods to generate the file hash.

Requirements

VersionWindows Installer 5.0 on Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003, Windows XP, and Windows 2000. See the Windows Installer Run-Time Requirements for information about the minimum Windows service pack that is required by a Windows Installer version.
HeaderMsi.h
LibraryMsi.lib
DLLMsi.dll
Unicode and ANSI namesMsiGetFileHashW (Unicode) and MsiGetFileHashA (ANSI)

See Also

MsiFileHash table
MSIFILEHASHINFO
Default File Versioning

Send comments about this topic to Microsoft

Build date: 8/13/2009

© 2009 Microsoft Corporation. All rights reserved.