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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值