InstallShield如何做Excel安装与否的检测

  • 传统的方法

  一般都会从注册表入手,检测注册表中是否存在某项来判断是否安装了Office,还可以通过注册表信息来判断安装的具体版本。

  • 存在的问题

  由于系统的不同、注册表的损坏、安装包的不同等等原因,读取注册表的方法显得不靠谱了。

  • 最后的方法

  当注册表检测的结果是没有安装后,再来创建一个Excel实例,如果创建成功了,那么说明安装过。

  有人会问,为什么不一开始就直接创建实例,我的回答是创建Excel实例比较耗内存,注册表有效的情况下检测够用了。

  • 最后贴上代码
//---------------------------------------------------------------------------
// DoesExcelExist
// 判断是否安装了Excel
//---------------------------------------------------------------------------
function BOOL DoesExcelExist()
BOOL bResult;
begin 
REGDB_OPTIONS = REGDB_OPTIONS & ~REGDB_OPTION_WOW64_64KEY; 
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);	
if(RegDBKeyExist("SOFTWARE\Wow6432Node\Microsoft\Office\Excel")<0 ) then
_out("64 system does not have Excel, now check 32 system.");
if(RegDBKeyExist("SOFTWARE\Microsoft\Office\Excel")<0 ) then
_out("32 system does not have Excel too, Now check is could create Excel object."); 
if(!CreateExcelObject())then
_out("So this system does not have Excel, return false.");
bResult = FALSE;
else
_out("So this system have Excel, return true.");
bResult = TRUE;
endif; 
else 
_out("32 system have Excel, return.");
bResult = TRUE;
endif; 
else 
_out("64 system have Excel, return.");
bResult = TRUE;
endif; 
REGDB_OPTIONS = REGDB_OPTIONS | REGDB_OPTION_WOW64_64KEY;
return bResult;
end;

//---------------------------------------------------------------------------
// CreateExcelObject
// 创建Excel实例
// 通过成功与否来判断是否安装了Excel
//---------------------------------------------------------------------------
function BOOL CreateExcelObject()	
OBJECT excelObj; 
begin 
set excelObj = CreateObject("Excel.Application");//创建一个Excel对象 
if (IsObject(excelObj) = FALSE ) then
_out("Create Excel object failed.");
set excelObj = NOTHING;
return FALSE;
endif; 
_out("Create Excel object successe.");
set excelObj = NOTHING;
return TRUE;
end;
严以律己、宽以待人
原文地址:https://www.cnblogs.com/kuang17/p/4423333.html