Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public string findComponentCode(string productCode, string ComponentName)
  2. {
  3. int pathLen = 512;
  4. StringBuilder path = new StringBuilder(pathLen);
  5. IntPtr phDatabase = IntPtr.Zero;
  6. IntPtr hView = IntPtr.Zero;
  7. IntPtr hRecord = IntPtr.Zero;
  8. int componentCodeLen = 512;
  9. StringBuilder componentCode = new StringBuilder(componentCodeLen);
  10.  
  11. MsiGetProductInfo(productCode, "LocalPackage", path, ref pathLen);
  12. MsiOpenDatabase(path.ToString(), IntPtr.Zero, ref phDatabase);
  13. MsiDatabaseOpenView(phDatabase, "SELECT * FROM `Component`", ref hView);
  14. MsiViewExecute(hView, hRecord);
  15. while (MsiViewFetch(hView, ref hRecord) != 259)
  16. {
  17. int bufferLen = 512;
  18. StringBuilder buffer = new StringBuilder(bufferLen);
  19.  
  20. MsiRecordGetString(hRecord, 1, buffer, ref bufferLen);
  21. if (String.Compare(buffer.ToString(), ComponentName) == 0)
  22. {
  23. MsiRecordGetString(hRecord, 2, componentCode, ref componentCodeLen);
  24. break;
  25. }
  26. }
  27. MsiViewClose(hView);
  28. MsiCloseHandle(hRecord);
  29. MsiCloseHandle(phDatabase);
  30. return componentCode.ToString();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement