代码改变世界

HOWTO:InstallShield中如何判断IIS是否安装以及安装的版本

2010-11-16 23:41  Kevin.Wan  阅读(3271)  评论(3编辑  收藏  举报

版权声明: 可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息。 

近期被问及在InstallShield的脚本中如何判断IIS(Internet Information Services)是否被安装,或者是判断目标机上安装的IIS版本。

我们这里是通过读取注册表的方式来进行判断。

对于Basic MSI或InstallScript MSI工程,还可以通过IIS_VERSION属性进行判断,大家有兴趣可以去琢磨一下。

下面是通过注册表方式判断的示例代码(我们在事件响应函数OnAppSearch进行判断)

function OnAppSearch()
    
STRING szKey, szName, svValue, szMsg;
    
NUMBER nvType, nvSize, nvVersion;
begin
    
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE); 
    szKey = "SOFTWARE\\Microsoft\\InetStp";          
    szName = "MajorVersion";
    nvType = REGDB_STRING;
    
if(RegDBGetKeyValueEx(szKey, szName, nvType, svValue, nvSize) < 0then
        szMsg = "Please add this role in Server Manager and then run this setup again.";     
        
MessageBox(szMsgSEVERE);
        
abort;
    
else
        
StrToNum(nvVersion, svValue); 
        
if ( nvVersion < 6 ) then
            szMsg = "Please install IIS 6.0 or higher and then run this setup again.";     
            
MessageBox(szMsg, SEVERE);
            
abort;
        
endif;
    
endif;
end;