Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

MsiEvaluateCondition


7 replies to this topic

mikebsr

mikebsr
  • Members
  • 19 posts

Posted 09 November 2001 - 21:03

I am attempting to use the MsiEvaluateCondition function in a deferred CA to conditionally clean up a few things after files have been installed (regsvr, etc). When I run "nResult = MsiEvaluateCondition(hMSI, "&Disuse=3");" in immediate, it works just fine. When I run this same line in deferred, it returns an error. Is there any way to get the feature state with a deferred CA, or am I doing something wrong?

Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 13 November 2001 - 16:20

That is not possible in a deferred action.

You can pass the required information in with CustomActionData


mikebsr

mikebsr
  • Members
  • 19 posts

Posted 15 November 2001 - 21:14

Thanks for the help. I figured that out. But I have about 6 different conditions to monitor. So, I ended up saving all my important setup data in the immediate custom actions to a file, then read that file later in the deferred actions. Seems to work ok...

Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 15 November 2001 - 23:05

That will work but it is improper code.   In a correctly formed installation you must not write any files or registry data to the machine except in a deferred or commit action.  Why?  Suppose your install fails for some unforseen reason.  Your file is not cleaned up.

The correct way is for your immediate actions to define a property with the same name as your deferred custom action then the custom action can read this property with MsiGetPropery(hMsi, "CustomActionData", pString, &Length);


mikebsr

mikebsr
  • Members
  • 19 posts

Posted 16 November 2001 - 15:00

So, if I have multiple settings I need to save (variable values), I should build some delimted string, write it to the CustomActionData property, and parse it later?

Thanks much for your advice on this. I'm just trying to understand everything I can. I would much rather do it the "correct" way.


Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 16 November 2001 - 15:41

Yes, that is what I do. (Not that everyyhing I do is correct).  

Since you are still learning about deffered custom actions I will point out another issue beginners often miss out (I did).  I am not implying you do not know this already.  If the installation fails later your CA will be called again to undo the changes it made.  So you must at least prevent the CA from running again or ideally reverse your action.

A deferred CA should have the broad structure

UINT _stdcall GreatStuff(MSIHANDLE hInstaller)
{
 if (MsiGetMode(hInstaller, MSIRUNMODE_ROLLBACK))
 {
    //  Installation has failed
    //  Add code to undo what the CA did here
 }
 else
 {
    // Add code to perform the CA here
 }
 return ERROR_SUCCESS;
}



mikebsr

mikebsr
  • Members
  • 19 posts

Posted 16 November 2001 - 16:56

Thanks....does MsiGetMode work if the action is deferred?

Ian Blake

Ian Blake
  • Members
  • 483 posts

Posted 16 November 2001 - 17:37

Like most things in deferred MsiGetMode it is limited.  You can certainly check MSIRUNMODE_SCHEDULED, MSIRUNMODE_COMMIT, or MSIRUNMODE_ROLLBACK.  You can not do anyhing else with it.

see MSI docs

Windows Installer
 Custom Actions
    Using Custom Actions
       Obtaining Context Information for Deferred Execution Custom Actions