Parse MSI installers by call MSI database [C#]

简介:

Purpose: Parse MSI installer, to get information such as product name, product code, properties etc.

MSI is a standard windows install techonoly, so there are APIs for developers to access. But they are c/c++ methods, instead of C#. After google, i found the ‘Wrapping the Windows Installer 2.0 API’(http://www.codeproject.com/KB/cs/msiinterop.aspx), which is can let .net developers access MSI api easily.

After download the library, you can visit MSI datatable like this

 

 1:  using System;
 2:  using WindowsInstaller;
 3:   
 4:  namespace MsiTest
 5:  {
 6:      class Program
 7:      {
 8:          static void Main(string[] args)
 9:          {
10:              test("c:\\xxx.msi");
11:          }
12:   
13:          private static void test(string fileName)
14:          {
15:              IntPtr databasePtr;
16:              var retDatabase = MsiInterop.MsiOpenDatabase(fileName, MsiDbPersistMode.ReadOnly, out databasePtr);
17:   
18:              IntPtr viewPtr;
19:              var ret = MsiInterop.MsiDatabaseOpenView(databasePtr, "SELECT Value FROM Property where Property = 'SecureCustomProperties'", out viewPtr);
20:   
21:              IntPtr recordPtr = IntPtr.Zero;
22:              ret = MsiInterop.MsiViewExecute(viewPtr, IntPtr.Zero);
23:              ret = MsiInterop.MsiViewFetch(viewPtr, ref recordPtr);
24:   
25:              uint buffer_length = 2550;
26:              string return_buffer = new string(' ', (int)buffer_length);
27:              MsiInterop.MsiRecordGetString(recordPtr, 1, return_buffer, ref buffer_length);
28:              MsiInterop.MsiCloseAllHandles();
29:   
30:              Console.WriteLine(return_buffer.Trim());
31:          }
32:   
33:      }
34:  }
35:   
36:   


本文转自Jack Niu博客园博客,原文链接:http://www.cnblogs.com/skywind/archive/2011/11/17/2252617.html,如需转载请自行联系原作者
相关文章
|
5月前
|
数据库管理 Windows
【CodeSmith】The System.Data.SQLite library is not installed on this computer,不能使用SQLite解决办法
【CodeSmith】The System.Data.SQLite library is not installed on this computer,不能使用SQLite解决办法
21 0
|
9月前
|
安全
[-] .\Navicat-Cracker NavicatCrackerDlg.cpp:332 -3All patch solutions are suppressed. Patch abort!HI
[-] .\Navicat-Cracker NavicatCrackerDlg.cpp:332 -3All patch solutions are suppressed. Patch abort!HI
1629 0
cl.exe is unable to create an executable file
cl.exe is unable to create an executable file
103 0
重装驱动:Failed to initialize NVML: Driver/library version mismatch
重装驱动:Failed to initialize NVML: Driver/library version mismatch
545 0
|
内存技术 芯片
MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL
MDK st-link下载STM32程序出现Internal command error和Error:Flash download failed. Target DLL   是因为目标板的芯片处于休眠的状态,在尝试连接目标板时候也会出现报错Internal command ...
3502 0
|
SQL Oracle 关系型数据库
关于数据库安装的问题SP2-0667: Message file sp1.msb not found
昨天自己在OEL上准备把10g,11g的环境都准备一下,我规划了一下硬盘空间,然后创建了相应的用户,12c的Oms也在这次的范围之内。 drwx------  4 oms10g  dba     4096 Jan 18 20:56 oms10g...
3190 0
|
缓存
HALCON error #5190: Invalid window parameter的解决办法(需要hcanvas.dll文件)
HALCON error #5190: Invalid window parameter的解决办法(需要hcanvas.dll文件)
629 0
|
Linux 异构计算
成功解决./nvidia-installer: invalid option: "‐‐no‐opengl‐files" ERROR: Invalid commandline, please run `
成功解决./nvidia-installer: invalid option: "‐‐no‐opengl‐files" ERROR: Invalid commandline, please run `
Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, se
错误提示: Severity Code Description Project File Line Suppression StateError This project references NuGet package(s) that are missing on this computer.
994 0