0

Is it possible to programmaticaly (C#) obtain a hashsum of files contained in a MSI package using Microsoft.Deployment.WindowsInstaller or Microsoft.Deployment.WindowsInstaller.Package dlls?

I am getting files using this method: How can I resolve MSI paths in C#?

And not to extract files onto FS, I would like to get a hashsum of files using C# code.

Is it possible?

Community
  • 1
  • 1
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Jul 17 '13 at 19:17

1 Answers1

3

Windows Installer contains the MsiFileHash table. It gets populated at build time with 128-bit hashes of all files in the File table. The InstallPackage Files property brings back a dictionary of of InstallPathMap objects. The keys of this collection have the File key from the File table and that can be used to query the MsiFileHash to get the hash.

If you need to calculate the hash of an installed file for comparison against this stored hash, the Installer class found in Microsoft.Deployment.WindowsInstaller has the GetFileHash method that class the underlying MsiGetFileHash function.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
  • Hello Christopher! Thank you very much for such detailed answer! It really helped me to get hashcodes from files, which are "zipped" into MSI package. Also it helped to get the hashcodes of files on filesystem. But I've got one more question. Should the hashcodes of files in MSI and on FS be equal? Or they are different? – user2466851 Jul 18 '13 at 11:48
  • Not always. MSI has a series of rules that it follows when deciding to overwrite a file. This is to prevent DLL hell. For example you might be installing C:\Windows\System32\SomeShared.dll and have 1.0 to offer but 2.0 is present. In this case MSI will not overwrite the DLL so the hashes will be different. – Christopher Painter Jul 18 '13 at 12:09
  • Thank you very much Christopher! You helped me a lot! – user2466851 Jul 18 '13 at 13:20