SetupFactory安裝前卸載舊版本

在Install Actions中的On Startup中加入代碼:

--首先卸載系統中已安裝的版本
regBasePath = "Software\\"..SessionVar.Expand("%ProductName%");
if (Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, regBasePath)) then
	Dialog.Message("已存在舊版本", "已存在舊版本,請先卸載舊版本再安裝。", MB_OK, MB_ICONEXCLAMATION);
	Uninstaller = Registry.GetValue(HKEY_LOCAL_MACHINE, regBasePath, "Uninstaller", true);
	UninstallData = Registry.GetValue(HKEY_LOCAL_MACHINE, regBasePath, "UninstallData", true);
	Shell.Execute(Uninstaller, "", UninstallData, "");
	Application.Exit();
end

在Install Actions中的On Post Install中加入代碼:

--創建卸載信息,方便下次重安裝時卸載
regBasePath = "Software\\"..SessionVar.Expand("%ProductName%");
Registry.CreateKey(HKEY_LOCAL_MACHINE, regBasePath);
Registry.SetValue(HKEY_LOCAL_MACHINE, regBasePath, "Uninstaller", SessionVar.Expand("%AppFolder%\\uninstall.exe"), REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, regBasePath, "UninstallData", SessionVar.Expand("\"/U:%AppFolder%\\Uninstall\\uninstall.xml\""), REG_SZ);
Registry.SetValue(HKEY_LOCAL_MACHINE, regBasePath, "Version", SessionVar.Expand("%ProductVer%"), REG_SZ);

在Uninstall Actions中的On Post Uninstall中加入代碼:

--刪除註冊表信息
regBasePath = "Software\\"..SessionVar.Expand("%ProductName%");
if (Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, regBasePath)) then
	Registry.DeleteKey(HKEY_LOCAL_MACHINE, regBasePath);
end

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章