安装包卸载时如何删除安装时写在系统环境变量中的内容
在用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)?<0)?then?? ?
?? ??? ?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,然后再設回去。
?
?
轉載于:https://www.cnblogs.com/kivenhou/archive/2011/06/07/2074203.html
總結
以上是生活随笔為你收集整理的安装包卸载时如何删除安装时写在系统环境变量中的内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kubernetes权威指南精彩段落
- 下一篇: 基于Spark的电影推荐系统(推荐系统~