Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string findComponentCode(string productCode, string ComponentName)
- {
- int pathLen = 512;
- StringBuilder path = new StringBuilder(pathLen);
- IntPtr phDatabase = IntPtr.Zero;
- IntPtr hView = IntPtr.Zero;
- IntPtr hRecord = IntPtr.Zero;
- int componentCodeLen = 512;
- StringBuilder componentCode = new StringBuilder(componentCodeLen);
- MsiGetProductInfo(productCode, "LocalPackage", path, ref pathLen);
- MsiOpenDatabase(path.ToString(), IntPtr.Zero, ref phDatabase);
- MsiDatabaseOpenView(phDatabase, "SELECT * FROM `Component`", ref hView);
- MsiViewExecute(hView, hRecord);
- while (MsiViewFetch(hView, ref hRecord) != 259)
- {
- int bufferLen = 512;
- StringBuilder buffer = new StringBuilder(bufferLen);
- MsiRecordGetString(hRecord, 1, buffer, ref bufferLen);
- if (String.Compare(buffer.ToString(), ComponentName) == 0)
- {
- MsiRecordGetString(hRecord, 2, componentCode, ref componentCodeLen);
- break;
- }
- }
- MsiViewClose(hView);
- MsiCloseHandle(hRecord);
- MsiCloseHandle(phDatabase);
- return componentCode.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement