一、主要思想是:
1、在初始化OnSetTARGETDIR函数中,if( MAINTENANCE ) then的条件中调用卸载函数(UninstallOldVersion);
2、在卸载函数中需要判断是否装有旧版本,给出提示框,访问用户是否要卸载;
3、卸载函数主要是通过GUID找到对应的程序安装路径、InstallShield卸载文件夹路径、将这些文件夹删除,然后删除快捷方式,再删除对应的注册表;
4、删除完成后,通过进程ID找到对应安装EXE的全路径,运行这个EXE程序,然后退出当前EXE程序。
注:GUID一定要是固定的。
二、相关卸载函数
1、函数声明:
prototype NUMBER KillProcess(string);
prototype BOOL GetProcessRunning(string, int, BYREF string);
prototype UninstallOldVersion();
prototype DeleteUninstallShortcut();
prototype Shell32.SHChangeNotify(LONG, LONG, POINTER, POINTER);
prototype Kernel32.GetCurrentProcessId();
2、函数定义:
function DeleteUninstallShortcut()
string strCmdLine, strProductFolder, strIconPath, strItemName,svPath;
begin
strProductFolder = "产品名称";
DeleteFolderIcon(FOLDER_PROGRAMS ^ strProductFolder,"产品名称");
DeleteFolderIcon(FOLDER_PROGRAMS ^ strProductFolder,"卸载产品名称");
DeleteFolderIcon(FOLDER_DESKTOP,"产品名称");
DeleteProgramFolder(FOLDER_PROGRAMS ^ strProductFolder);
end;
function UninstallOldVersion()
string szPath,UninstallString;
string szNumName,szNumValue;
number nType,nSize,nIgnore,nResult;
string szmsg1;
int nIndex;
string oldGuid;
string szTARGETDIR;
STRING noUse;
NUMBER szProcessId;
STRING szModuleName; // Module filename
begin
oldGuid = "{1F1C2DFC-2D24-3E06-BCB8-725134ADF989}";
szPath=WINDIR+"Installer\\"+oldGuid;
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
UninstallString="\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\"+oldGuid;
nType=REGDB_STRING;
szNumName="UninstallString";
nResult = VerProductCompareVersions();
RegDBGetKeyValueEx(UninstallString,szNumName,nType,szNumValue,nSize); //获取卸载脚本
if(RegDBKeyExist(UninstallString)>0 && nResult != VERSION_