How to retain service settings through InstallShield upgrade install

北战南征 提交于 2019-11-30 18:58:07

问题


I have an InstallScript project in IS2010. It has a handful of services that get installed. Some are C++ exes and use the "InstallShield Object for NT Services". Others are Java apps installed as services with Java Service Wrapper through LaunchAppAndWait command line calls. Tomcat is also being installed as a service through a call to its service.bat.

When the installer runs in upgrade mode, the services are reinstalled, and the settings (auto vs. manual startup, restart on fail, log-on account, etc.) are reverted to the defaults.

I would like to save the service settings before the file transfer and then repopulate them afterward, but I haven't been able to find a good mechanism to do this. How can I save and restore the service settings?


回答1:


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

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;


来源:https://stackoverflow.com/questions/2900507/how-to-retain-service-settings-through-installshield-upgrade-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!