How to save service settings by installing InstallShield updates

I have an InstallScript project in IS2010. It has several services that are installed. Some of them are C ++ versions and use the "InstallShield Object for NT Services". Others are Java applications installed as services with Java Wrapper through LaunchAppAndWait command line calls. Tomcat is also installed as a service by calling its service.bat.

When the installer runs in update mode, the services are reinstalled and the settings (automatic or manual start, restart upon failure, account, etc.) are returned to their default values.

I would like to save the service settings before transferring the file, and then re-populate them later, but I could not find a good mechanism for this. How to save and restore service settings?

+3
source share
1 answer

I got this working by reading service information from the registry in OnUpdateUIB before storing it in a global variable, and writing information back to the registry in OnUpdateUIAfter.

the code:

export prototype void LoadServiceSettings();
function void LoadServiceSettings()
number i, nResult;
string sServiceNameArray(11), sRegKey, sTemp;
BOOL bEntryFound;
begin
PopulateServiceNameList(sServiceNameArray);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
//write service start values to the registry
for i = 0 to 10
    if (ServiceExistsService(sServiceNameArray(i))) then
        sRegKey = "SYSTEM\\CurrentControlSet\\Services\\" + sServiceNameArray(i);
        nResult = RegDBSetKeyValueEx(sRegKey, "Start", REGDB_NUMBER, sServiceSettings(i), -1);
        if(nResult < 0) then
            MessageBox ("Unable to save service settings: " + sServiceNameArray(i) + ".", SEVERE);
        endif;
    endif;
endfor;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT); //set back to default
end;

export prototype void SaveServiceSettings();
function void SaveServiceSettings()
number i, nType, nSize, nResult;
string sServiceNameArray(11), sRegKey, sKeyValue;
begin
PopulateServiceNameList(sServiceNameArray);
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
for i = 0 to 10
    if (ServiceExistsService(sServiceNameArray(i))) then
        //get service start values from registry
        sRegKey = "SYSTEM\\CurrentControlSet\\Services\\" + sServiceNameArray(i);
        nResult = RegDBGetKeyValueEx(sRegKey, "Start", nType, sKeyValue, nSize);
        if(nResult < 0) then
            MessageBox ("Unable to save service settings: " + sServiceNameArray(i) + ".", SEVERE);
        endif;
        sServiceSettings(i) = sKeyValue;
    endif;
endfor;
RegDBSetDefaultRoot(HKEY_CLASSES_ROOT); //set back to default
end;
+4
source

Source: https://habr.com/ru/post/1746914/


All Articles