cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
oded_rabani
Level 3

How to set enviroment value and use it by other function ?

Hi all,

I am using Basic MSI project.
I wrote a function which ask the user to provide username and password, I would like to use this user name and password in other functions as well.

Since it is not wise to write it to a file, I would like to know if there is any way to set an environment value and use it in any other function.

if some one could give my example it will be great

Thanks !
Oded
Labels (1)
0 Kudos
(5) Replies
RobertDickau
Flexera Alumni

Perhaps set properties with MsiSetProperty and later read the values back with MsiGetProperty? The documentation and these forums have many examples.

(If you do use properties, you might eventually look into using MsiHiddenProperties to prevent the values from being written to an MSI log file.)
0 Kudos
oded_rabani
Level 3

Thanks for the quick reply, I will check it !
0 Kudos
oded_rabani
Level 3

Hi again,

Below is my code, there are three functions:

1. GetGlobalUsername - ask the end user to provide username and password and store it using MsiSetProperty.
2. ChangeCredentials - which should configure COM+ application using the information stored at MsiSetProperty
3. Install_services - install services and configure the username which run it.

I was trying using MsiSetProperty and MsiGetProperty but for some reason MMusername and MMpassword are blank 😞 in ChangeCredentials and Install_services.

Since I am new with installshield, and not that sure what I'm doing, I hope someone will be able to assist...

Thanks in advance
Oded





// Include Ifx.h for built-in InstallScript function prototypes. 
#include "Ifx.h"



//******************************
//GLOBAL PROTOTYPE AND FUNCTIONS
//******************************
export prototype GetGlobalUsername(HWND);
export prototype ChangeCredentials(HWND);
export prototype Install_services(HWND);


//global var
NUMBER svresult, defualt, nresult,nsize ;
NUMBER nSize;
STRING MMusername, MMpassword, password, username;



/*----------------------------------------------------------*\
* This script get the user name and password
\*-----------------------------------------------------------*/


function GetGlobalUsername (hMSI)

STRING defualt_user, defult_password,szMsg,szdefult, password1, password2;


begin

ask_username:
szMsg="Specify the user name to be used for running COM+ Applications ans Windows services.The user name should be in the form DOMAIN\\Username." ;
defualt_user="AG\\defualt-user-name";
AskText(szMsg,defualt_user,username);
szMsg="Are you sure you want to use "+username+" as user name?";
if (AskYesNo(szMsg, YES) = NO) then
goto ask_username;
endif;

ask_password:
szMsg="Please specify the password for "+username ;
defult_password="";
EnterPassword(szMsg,defult_password, password1);

szMsg="Please verify the password" ;
szdefult="";
EnterPassword(szMsg,defult_password, password2);

if (password1=password2) then

goto continue;
else
MessageBox ("Password does not match, please enter it again.", INFORMATION);
goto ask_password;
endif;

continue:
password=password1;

//save the username and password in MSI properties
MsiSetProperty (hMSI, "USERNAME",username);
MsiSetProperty (hMSI, "PASSWORD",password);


end;


/*----------------------------------------------------------*\
* This script set the COM+ credentials
\*-----------------------------------------------------------*/


function ChangeCredentials (hMSI)

STRING vbscript, argument;

begin
vbscript ="C:\\MM\\Install\\COM+\\ChangeCredentials.vbs " ;

MsiGetProperty (hMSI, "USERNAME", MMusername, nSize);
MsiGetProperty (hMSI, "PASSWORD", MMpassword, nSize);


argument=MMusername+" "+MMpassword;

//change the Credentials
LaunchAppAndWait ("cscript" ,vbscript+argument, WAIT);



end;




/*----------------------------------------------------------*\
* This script will install the service and configure it
\*-----------------------------------------------------------*/

function Install_services (hMSI)


NUMBER nRootKey, nResult;
STRING SC,CONFIG,ServiceName, ServiceDisplayName, ServiceDescription, ServicePathFile, StartServiceArgs;
BOOL StartService;

begin
//set SC and config, dont forget to have space at the end of SC
SC="C:\\WINDOWS\\system32\\sc.exe ";
CONFIG="config";

//declare the Service (Myservice)
ServiceName = "Myservice";
ServiceDisplayName = "Myservice";
ServiceDescription = "This service is incharge for blablabla";
ServicePathFile = "c:\\Projects\\MMNew\\Shared\\Dll\\Myservice.exe";
StartService = TRUE;
StartServiceArgs = "";

//check if the service exists if not, install it
if (ServiceExistsService ( ServiceName )= FALSE)
then ServiceAddService ( ServiceName, ServiceDisplayName, ServiceDescription, ServicePathFile, StartService, StartServiceArgs );
MessageBox (ServiceName +" has been installed", INFORMATION);
else
MessageBox (ServiceName +" already installed", INFORMATION);
endif;

MsiGetProperty (hMSI, "USERNAME", MMusername, nSize);
MsiGetProperty (hMSI, "PASSWORD", MMpassword, nSize);



//config the service username and password
LaunchAppAndWait (SC,CONFIG+" "+ServiceName+" obj= "+MMusername+" password= "+MMpassword , WAIT);


//remove then service in case of uninstall
if MAINTENANCE then
ServiceRemoveService (ServiceName);
endif;

end;

0 Kudos
ISNewone
Level 3

Was hMSI set to ISMSI_HANDLE?
0 Kudos
RobertDickau
Flexera Alumni

You might need to set the buffer-size variable to a value larger than the string length before each call to MsiGetProperty; please search the InstallShield help for "MsiGetProperty" to see some examples...
0 Kudos