问题描述:
使用Intallshield的InstallScript MSI Project工程制作的安装包
卸载或者原地址更新某程序时,需要判断安装程序是否正在使用。
解决方案:
在OnMaintUIBefore和OnResumeUIBefore内的适当位置调用如下函数,返回为0则退出安装程序,否则即继续。
function NUMBER CheckFilesInUse()
STRING szTitle, szMsg, szPath;
LIST listID;
NUMBER nReturn;
BOOL bDone;
NUMBER nRet;
begin
szMsg = "The following applications are currently locking files";
szPath = XX; //需要检查的文件所在的完整路径
bDone = FALSE;
nRet = 1;
while (!bDone)
if (Is(FILE_LOCKED, szPath)) then
// create a string list
listID = ListCreate(STRINGLIST);
// if an error occurred, report it; then terminate.
if (listID = LIST_NULL) then
MessageBox("Unable to create list.", SEVERE);
abort;
endif;
ListAddString(listID, "名称", AFTER);
// display the Files in Use dialog.
nReturn = SdFilesInUse(szTitle, szMsg, szPath, listID);
// if user clicks RETRY, show locked-file dialog again;
// otherwise, let the file-transfer process handle it, which might require a reboot
switch (nReturn)
case IDABORT:
bDone = TRUE;
nRet = 0;
case IDCANCEL:
bDone = TRUE;
nRet = 0;
case IDRETRY:
bDone = FALSE;
nRet = 1;
case IDIGNORE:
bDone = TRUE;
nRet = 1;
endswitch;
// remove the list from memory
ListDestroy(listID);
else
bDone = TRUE;
endif;
endwhile;
return nRet;
end;
为了避免用户点击忽略时产生的其他的问题,在Dialogs中编辑SdFilesInUse对话框,将其中的忽略按钮禁用并隐藏。