[DllImport("Msi.dll", SetLastError = true)]
static extern uint MsiGetPatchInfoEx(
String szPatchCode,
String szProductCode,
String szUserSid, //pass 'null' to omit.
MSIINSTALLCONTEXT dwContext,
String szProperty,
[Out] StringBuilder lpValue,
ref uint pcchValue
);
Declare Function MsiGetPatchInfoEx Lib "msi.dll" (TODO) As TODO
None.
Do you know one? Please contribute it!
None.
Please add some!
const uint CURRENT_USER_SID = 0;
const string INSTALLPROPERTY_INSTALLDATE = "InstallDate"; // string value from MSDN
uint pcchValue = 1024*1024;
StringBuilder returnValue = new StringBuilder((int)pcchValue);
uint rv;
rv = MsiGetPatchInfoEx(
patch_id,
product_id,
CURRENT_USER_SID,
MSIINSTALLCONTEXT.Machine, // defined below
INSTALLPROPERTY_INSTALLDATE,
returnValue,
ref pcchValue
);
///
private string TranslateMsiError(int msiError)
{
switch (msiError)
{
case 5 : return Resources.MsiErrorAccessDenied ;
case 1610: return Resources.MsiErrorBadConfiguration ;
case 1627: return Resources.MsiErrorFunctionFailed ;
case 87: return Resources.MsiErrorInvalidParameter ;
case 234: return Resources.MsiErrorMoreData ;
case 0: return Resources.MsiErrorSuccess ;
case 1605: return Resources.MsiErrorUnknownProduct ;
case 1608: return Resources.MsiErrorUnknownProperty ;
case 1647: return Resources.MsiErrorUnknownPatch ;
default:
break;
}
return Resources.AgentErrorUnknown;
}
enum MSIINSTALLCONTEXT
{
// Query that is extended to all per–user-managed installations for the users that szUserSid specifies.
UserManaged= 1,
// Query that is extended to all per–user-unmanaged installations for the users that szUserSid specifies.
UserUnmanaged=2,
// Query that is extended to all per-machine installations.
Machine=4
}