This is a general rule of thumb for when to use Deferred in System Context Custom Actions. Now remember, this is a rule of thumb, not an absolute.
I have noticed that newcomers to custom action programming are often not clear when to declare a custom action to be Deferred in System Context. First off, what does Deferred in System Context mean?
When you create a custom action, one setting that must be configured is the In-Script Execution setting on the Respond Options panel of the Custom Action Wizard. Actions are executed in the order in which they appear in the sequence. However, the sequences are run many times during a typical installation. So, the execution setting becomes very important.
The types of execution are:
- Immediate Execution
- Deferred Execution
- Rollback Execution
- Commit Execution
- Deferred Execution in System Context
Custom actions that set properties, feature states, component states, or target directories, or that schedule system operations by inserting rows into sequence tables, can in many cases use immediate execution safely.
Custom actions that change the system directly, or call another system service, must be deferred to the time when the installation script is executed. The key phrase here is “custom actions that change the system directly”. That is the trickier part for newcomers to judge. Whether their custom action does or does not change the system directly.
Let’s say you create an InstallScript custom action that performs some function. You feel that it should be able to be run with Immediate Execution, so you declare it as such. You run your installation and at the point when the custom action is executed, nothing happens. You are really disappointed and wonder what could have happened? There are at least two possible causes to your problem.
The first possible cause is that is you may have inserted your custom action in the wrong place in the Execute sequence. It happens, especially when you are new to writing custom actions.
The second potential problem is that you should have declared it as Deferred in System Context.
Therefore, the rule of thumb is this. If you know you have inserted your custom action in an appropriate place in the sequence, yet the desired result does not occur upon execution, you may need to change the execution to Deferred in System Context.
Like I said, it’s not an absolute. But that one thing has often been the cure for my custom action problems.