Reputation: 8659
I have InstallScript code that executes a particular task. The task will either work or will not work. If the task works, I want to set a global variable to 1. If it does not work, I want to set a global variable to 0.
Somewhere down the line, I have another InstallScript code that executes. What I want is to check the global variable to see if it's 1. If it is, fire off that code.
I know that I can modify the Install Exec Condition, but what I do not know how to do is to check for a global variable. How I can accomplish this?
Upvotes: 2
Views: 7982
Reputation: 197
You can just declare a variable outside the function in .rul file, and the variable would be a global variable.
If you want to use the global variable in another .rul file, you have to include the rul file which declares the global variable.
ex.
/* featureevents.rul */
STRING globalVar; // declare a global variable
export prototype xxx_installed();
function xxx_installed()
STRING localVar; // declare a local variable
begin
end;
--
/* Setup.rul */
#include "featureevents.rul"
function OnFirstUIBefore()
begin
// use a global variable
globalVar="This is a global variable.";
MessageBox(globalVar, INFORMATION);
end;
I suggest you that add one or more resource header files, and put all the constants, global variables and function declaration in them.
/* featureevents.rul */
#include "CusRes.h"
...
--
/* Setup.rul */
#include "CusRes.h"
...
--
/* CusRes.h */
#ifndef _CUSRES_H_
#define _CUSRES_H_
// move the code to resource header file
STRING globalVar;
export prototype xxx_installed();
#endif //_CUSRES_H_
However, as Urman said, using property is a better way.
I miss the step of SecureCustomProperties, so I cannot get the value by MsiGetProperty() and use global variable instead.
But now I have got the information, and I'll also rewrite my code to use property instead.
Upvotes: -1
Reputation: 15905
In an InstallScript project, merely create and set a global variable, and code against it as you please.
If instead you are asking in the context of an MSI with custom actions that run InstallScript, you have to use MSI Properties as your global variables. Call MsiSetProperty to set it, and write your custom action's condition against that property. Or call MsiGetProperty to retrieve it in your code and do the conditional execution there. Note that if the first action is in the UI sequence and the second is in the Execute sequence, you should add any properties you use to the SecureCustomProperties
property.
To make this more concrete, your code might look like:
// Note: hInstall is the first parameter to your custom action
MsiSetProperty(hInstall, "RUN_SECOND_ACTION", "1");
and your condition in the custom action might be simply:
RUN_SECOND_ACTION
Upvotes: 2