安装包卸载时如何删除安装时写在系统环境变量中的内容

在用InstallShield制作安装包时,有时我们会在脚本中通过操作注册表,配置系统环境变量,比如在Path中追加,但卸载时如何清除追加的路径变量,一直有些模糊。

 

今天受网友启发,在InstallShield的帮助文档中找到了解决办法,代码如下:

function OnBegin()  
    
STRING svSearchPath;
begin
    // Set up the search path to pass as a parameter to PathSet. 
    svSearchPath 
= "C:\\DOS;C:\\WINDOWS;C:\\TEMP;" + 
                   
"D:\\Program Files\\Kevin Wan\\InstallShield;" + 
                   
"C:\\EXAMPLE\\SOURCE;D:\\WORK\\TEMP"

    // Initialize the path buffer. 
    
PathSet (svSearchPath); 

    // Display the initial search path. 
    // Delete D:\Program Files\Kevin Wan\InstallShield from the path buffer.                      

    if (PathDelete ("Kevin Wan"PARTIAL<0then    

        MessageBox ("First call to PathDelete failed.", SEVERE); 
    endif

    // Get the search path from the path buffer; this call also releases 
    
// the memory allocated for the path buffer. 

    PathGet (svSearchPath); 
    
MessageBox(svSearchPath, INFORMATION);
end;

这里我将Sample添加到了事件响应函数OnBegin中,大家实际操作时可以写到OnUninstall中。

Sample中我删除了和Kevin Wan相关的路径,但也要注意,这里最好选择唯一标示的字符串,否则可能会把其他程序写入的路径变量也同时删除了。

 以上转自:http://www.cnblogs.com/installshield/archive/2011/01/24/1943406.html

 

附:IS脚步增加环境变量实例

STRING  szKey , svValue;
NUMBER nvType , nvSize;

begin
    szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
    RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
    if(RegDBGetKeyValueEx(szKey,"Path",nvType,svValue,nvSize)=0) then           //读取Path
        svValue = "C:\\ABC;" + svValue; //添加路径
        if(RegDBSetKeyValueEx(szKey, "Path", REGDB_STRING, svValue, -1)<0) then //更新Path
            MessageBox ("Path add failed!", SEVERE);
        endif;
    endif;
end;
这样添加的话卸载的时候会产生一个问题,那就是整个Path变量都被删掉了(不是清空,而是整个删除)。解决办法有二:

1.首先你在你写path的那句话前后加上Disable(LOGGING); Enable(LOGGING);,表示阻止掉IS的安装日志,这样就不会记录你的动作,卸载时候也不会卸载掉path了
2.在卸载那里自己写脚本,读到path后去掉你自己的路径C:\ABC,然后再设回去。

 

 

posted @ 2011-06-07 12:00  天空行马  阅读(1519)  评论(0编辑  收藏  举报