杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2416|回复: 0

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

[复制链接]
发表于 2016-8-28 20:22:32 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
在用InstallShield制作安装包时,有时我们会在脚本中通过操作注册表,配置系统环境变量,比如在Path中追加,但卸载时如何清除追加的路径变量,一直有些模糊。
  1. function OnBegin()  
  2.     STRING svSearchPath;
  3. begin
  4.     // Set up the search path to pass as a parameter to PathSet.
  5.     svSearchPath = "C:\\DOS;C:\\WINDOWS;C:\\TEMP;" +
  6.                    "D:\\Program Files\\Kevin Wan\\InstallShield;" +
  7.                    "C:\\EXAMPLE\\SOURCE;D:\\WORK\\TEMP";

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

  10.     // Display the initial search path.
  11.     // Delete D:\Program Files\Kevin Wan\InstallShield from the path buffer.                     
  12.     if (PathDelete ("Kevin Wan", PARTIAL) <0) then   

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

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

  17.     PathGet (svSearchPath);
  18.     MessageBox(svSearchPath, INFORMATION);
  19. end;
复制代码

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

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


  1. STRING  szKey , svValue;
  2. NUMBER nvType , nvSize;

  3. begin
  4.     szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
  5.     RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
  6.     if(RegDBGetKeyValueEx(szKey,"Path",nvType,svValue,nvSize)=0) then           //读取Path
  7.         svValue = "C:\\ABC;" + svValue; //添加路径
  8.         if(RegDBSetKeyValueEx(szKey, "Path", REGDB_STRING, svValue, -1)<0) then //更新Path
  9.             MessageBox ("Path add failed!", SEVERE);
  10.         endif;
  11.     endif;
  12. end;
复制代码


这样添加的话卸载的时候会产生一个问题,那就是整个Path变量都被删掉了(不是清空,而是整个删除)。解决办法有二:

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






回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-6-17 11:13 , Processed in 0.489972 second(s), 22 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表