分享

InstallShield中IIS服务的检测和组件自动安装的实现

 icecity1306 2014-09-12
InstallShield中IIS服务的检测和组件自动安装的实现
    由于最近封装的安装程序里面需要涉及到数据库配置及IIS服务器配置等功能,数据库相关问题已经解决,但是IIS组件的自动安装一直没有搞定,今天去销售那里测试,虽然把很多安装过程都自动化了,他们也觉得现在这个安装版本比以前好用得多,可是心中始终觉得有点不爽:IIS自动安装始终没有实现。Google下,今天一定要把它搞定! 
    Google上先用Installshield和IIS关键字查找没找到多少可用信息,问的人还是不少,甚至老外也在问,可是没多少人回答。于是先从XP系统的实现上着手去找,添加/删除程序面板里面有个组件安装功能,运行它后可以运行系统的组件安装,在这里我们可以指定IIS的安装路径将IIS给手动装起来,突然想到,在添加/删除程序里面进行卸载时该面板属于不可操作状态,说明它们是关联一起的功能块,可是安装组件的时候能不能把添加/删除程序面板给关掉呢,于是偶试了一下:果然可以只留着组件添加面板而关闭添加/删除程序面板,这说明它们属于两个不同的功能块或者说是两个不同的程序控制,就从这里找突破口,看看进程“sysocmgr.exe”(system stand-alone optional component manager),系统可选组件安装管理,就是它了,看下它的参数: 
  /i:<master_oc_inf> - (必须的) 指定主 inf 的名称。以此作为安装的源路径。 
  /u:<unattend_spec> - 指定无人参予的操作参数 
  /r                 - 抑制重新启动(在需要重新启动时)。 
  /z                 - 显示跟随的参数不是 OC 参数且不需要传给组件。 
  /n                 - 强制将指定的主 inf 作为新的文件处理。 
  /f                 - 表明所有组件安装状态需要初始化,就象安装程序从未运行一样。 
  /c                 - 在安装的最后阶段不允许取消。 
  /x                 - 抑制  '初始化' 标题。 
  /q                 - 同 /u 一起使用。  运行没有界面的无人参与安装。   
  /w                 - 同 /u 一起使用。如果需要重新启动,提示用户而不要自动重新启动。 
  /l                 - 识别多种语言安装。 
再找下它的用法示例,于是我们可以用sysocmgr /i:sysoc.inf来调出组件安装界面,而后面那个/u:参数则是实现自动安装IIS的重中之重,它指定一个配置文件,里面写着用户事先定义好的安装/卸载组件,这样程序在读入该文件时就会对文件内的设置作相应处理,来看看用法: 
Sysocmgr.exe /i:sysoc.inf /u:x:\config.txt 
X:\config.txt就是用户事先定义好的配置文件,里面内容大致如下: 
[Components] 
iis_common = ON 
iis_www = ON 
iis_asp = ON 
iis_ftp = ON 
iis_inetmgr = ON 
aspnet= ON 
还要注意下列内容: 
[InternetServer] 
SvcManualStart = www 和/或 ftp 
PathFTPRoot = FTProot 的路径 
PathWWWRoot = WWWroot 的路径 
ApplicationDependency = ApplicationName, GroupID, GroupID 
ExtensionFile = 访问权限、路径、可删除的 UI、短说明、长说明 
DisableWebServiceOnUpgrade = True/False;该参数的默认值是 true。为了减少攻击风险,IIS 在升级之后处于关闭状态。可使用该无人参与安装参数使 IIS 在升级之后处于打开状态。 

这样写出配置文件并运行该命令后就可以弹出一个WINDOWS组件安装的界面并自动安装我们指定的组件了,可是还有一个问题就是,这样安装的话中间会不停地弹出让用户选择路径,这样就不是真正的无人值守安装了。MDSN上的解释是:
Note Windows always looks for the media that the server was originally installed from. If the server was installed from a CD, the unattended installation prompts you for the Windows CD. If you want to run the unattended installation and use media that is stored on a network share, you must change the value for the SourcePath subkey and the ServicePackSourcePath subkey in the following registry subkey: 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup
Change the values for the SourcePath subkey and the ServicePackSourcePath subkey to the appropriate network shares. The path must contain the i386 folder.
如果我们想将组件的安装位置指定于光盘以外的其它驱动/文件夹的话,必须更改那两项注册表值,并且该文件夹符合包含I386子文件夹的特征。这样将该两项值改为我们提供的IIS组件安装包,并把文件放至I386文件夹下,那么我们的IIS6无人值守功能就实现了,测试后成功安装IIS6组件,并且安装完毕后自动重启系统,加上/r属性,正常安装不重启,于是sysocmgr /i:sysoc.inf /r /u:x:\myConfig.txt 



下面是一个在InstallShield中实现IIS组件是否安装与未安装时自动安装IIS: 
prototype NUMBER CheckIIS(); 
prototype InstallIIS(); 

////////////////////////////////////////////////////////////////////////////// 
// FUNCTION: CheckIIS 
// 示例:检查系统是否安装IIS 
////////////////////////////////////////////////////////////////////////////// 
function NUMBER CheckIIS() 
     NUMBER nvType, nvSize; 
     STRING svvalue; 
begin 
     RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE ); 
     if (RegDBKeyExist ("System\\CurrentControlSet\\Services\\IISADMIN" ) = 1)then 
         return (1); 
     else 
         return (0); 
     endif; 
end; 

////////////////////////////////////////////////////////////////////////////// 
// FUNCTION: InstallIIS 
// 示例:安装IIS组件服务 
////////////////////////////////////////////////////////////////////////////// 
function NUMBER InstallIIS() 
begin 
   RegDBSetDefaultRoot ( HKEY_LOCAL_MACHINE ); 
   if (RegDBKeyExist ( "\\SOFTWARE\\Microsoft\\windows\\currentversion\\setup\\ServicePackSourcePath" )=1) then 
         RegDBDeleteKey ( "\\SOFTWARE\\Microsoft\\Windows\\currentversion\\setup\\ServicePackSourcePath" ); 
   endif; 
   RegDBSetKeyValueEx ( "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup" , "ServicePackSourcePath" , REGDB_STRING , SRCDIR^"iis6" , -1 ); 
   if (RegDBKeyExist ( "\\SOFTWARE\\Microsoft\\windows\\currentversion\\setup\\SourcePath" )=1) then 
         RegDBDeleteKey ( "\\SOFTWARE\\Microsoft\\Windows\\currentversion\\setup\\SourcePath" ); 
   endif; 
   RegDBSetKeyValueEx ( "\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup" , "SourcePath" , REGDB_STRING , SRCDIR^"iis6" , -1 ); 
   LaunchAppAndWait ( SystemFolder^"sysocmgr.exe" , "/i:sysoc.inf /r /u:\""+SRCDIR^"iis6\\config.txt\"" , LAAW_OPTION_WAIT ); 
end; 

安装处理脚本时: 
Dlg_IISCheck: 
    //显示即将进行安装条件检查 
    listTopics = ListCreate (STRINGLIST); 
    listDescriptions = ListCreate (STRINGLIST); 
    if (listTopics = LIST_NULL) || (listDescriptions = LIST_NULL) then 
        MessageBox("Unable to create lists.", INFORMATION); 
        abort; 
    endif;   
    ListAddString (listTopics, "Internet 信息服务(IIS):", AFTER); 
    ListAddString (listDescriptions, "Mircosoft Internet信息服务(IIS)提供基于网络的WWW服务", AFTER); 
     // Display the topics and descriptions. 
    nResult=SdDisplayTopics ( "程序运行软件环境", "请确认下列软件环境配置已完毕",listTopics,listDescriptions, 0); 
    // Remove the lists from memory. 
    ListDestroy (listTopics); 
    ListDestroy (listDescriptions); 
    if (nResult = BACK) then   
        goto Dlg_SdLincese; 
    else     
       //基础条件安装检查 
       if (CheckIIS()!=1) then 
          SdShowMsg ( "检测到系统尚未安装IIS组件,下面将自动安装IIS组件" , TRUE ); 
          InstallIIS(); 
          SdShowMsg ( "" , FALSE );         
          Delay( 1 ); 
       endif; 
    endif; 


MSDN上对于配置IIS文件格式及内容的说明,本例只用于XP安装,下面的配置设置好也可用于SERVER2003的IIS安装。 
Table B.1 lists the unattended installation parameters for IIS that you include in the [Components] section of the answer file. The default setting for all of the following parameters is off unless a component is required by some other component that you are installing. For example, if you are installing the World Wide Web Publishing Service (WWW service), then Common Files, IIS Manager, and network COM+ access are turned on by default. 
Table B.1   IIS Unattended Installation Parameters 
Parameter 
Description 
aspnet= on/off 
Enable ASP.NET . 
complusnetwork = on/off 
Enable network COM+ access. 
dtcnetwork = on/off 
Enable network Distributed Transaction Coordinator (DTC) network access. 
bitsserverextensionsisapi = on/off 
Enable the BITS Server Extensions ISAPI. 
bitsserverextensionsmanager = on/off 
Enable the BITS Server Extensions snap-in. 
iis_common = on/off 
Enable Common Files. 
iis_ftp = on/off 
Enable the File Transfer Protocol (FTP) service. 
fp_extensions = on/off 
Enable FrontPage?  2002 Server Extensions from Microsoft. 
iis_inetmer = on/off 
Enable IIS Manager. 
iis_nntp = on/off 
Enable the Network News Transfer Protocol (NNTP) service. 
iis_smtp = on/off 
Enable the Simple Mail Transfer Protocol (SMTP) service. 
iis_asp = on/off 
Enable Active Server Pages (ASP). 
iis_internetdataconnector = on/off 
Enable Internet Data Connector (IDC). 
sakit_web = on/off 
Enable Remote Administration (HTML). 
You cannot perform an unattended installation of this feature simultaneously with performing an unattended installation of the operating system. 
You can perform an unattended installation of this feature if you install IIS after you have installed the operating system by using the Sysocmgr.exe command-line utility. 
This feature is not available on Itanium-based computers running Windows XP 64-Bit Edition; the 64-bit version of Windows Server 2003, Enterprise Edition; or the 64-bit version of Windows Server 2003, Datacenter Edition. 
tswebclient = on/off 
Enable remote desktop Web connection. 
iis_serversideincludes = on/off 
Enable server-side includes (SSI). 
iis_webdav = on/off 
Enable WebDAV publishing. 
iis_www = on/off 
Enable the WWW service. 
appsrv_console = on/off 
Enable Application Server Console. 
This feature is not available on Itanium-based computers running Windows XP 64-Bit Edition. 
inetprint = on/off 
Enable Internet printing. 

Table B.2 lists the optional IIS unattended installation parameters. You include these parameters in the [InternetServer] section. 
Table B.2   Optional IIS Unattended Installation Parameters 
Parameter 
Description 
SvcManualStart = www and/or ftp 
If WWW or FTP is present, those services will be set to manual start. If you specify both www and ftp, separate them with a comma (,). When installed, the default service state is to automatically start. 
PathFTPRoot = path to FTProot 
Alternate path to which the FTP service is installed. The default is systemroot\Inetpub\Ftproot. 
PathWWWRoot = path to WWWroot 
Alternate path to which the WWW service is installed. The default is systemroot\Inetpub\Wwwroot. 
ApplicationDependency = ApplicationName, GroupID, GroupID 
Adds application and dependencies. 
For example: 
ApplicationDependency = CommerceServer, ASP, IndexingService 
ApplicationDependency = ExchangeServer, ASP60 
ApplicationDependency = MyApp, ASP.NET v1.1.4322 
This example makes Commerce Server dependent on ASP and the Indexing Service, Exchange Server dependent on ASP, and MyApp dependent on ASP.NET v1.1.4322. 
ExtensionFile = <Enabled Flag>,<File Path>[ ,<UI Deletable Flag> [ ,<Group ID> [ ,<Description> ] ] ] 
Specifies an extension file. The UI Deletable Flag, Group ID, and Description settings are all optional. However, if you specify any of the optional settings, you must include all of the previous settings. 
The parameters represent the following: 
Enabled Flag is set to 0 (zero) for disabled and 1 for enabled. 
File Pathis the path to the file, and it can contain environment variables. 
UI Deletable Flag specifies whether the item can be deleted using IIS Manager. Set to 0 for not deletable and 1 for deletable. 
Group ID allows you to group different dynamic-link libraries (DLLs) and Common Gateway Interfaces (CGIs) and have dependencies for the applications.   
Description is the description of the extension file. 
For example: 
ExtensionFile = 1, windir\MyISAPIS\Myisapi.dll, 1, MyGroup, My Custom ISAPI 
–Or– 
ExtensionFile = 1, windir\MyCGIs\Mycgi.cgi, 1, MyGroup, My Custom CGI 
DisableWebServiceOnUpgrade = True/False 
The default for this parameter is True for upgrades from the Microsoft? Windows? 2000 Server operating system, unless you have run the IIS Lockdown Tool or added the registry entry RetainW3SVCStatus to the registry. Please see Caution below. 
For more information about when the WWW service is disabled after an upgrade has been performed, see Upgrading an IIS Server to IIS 6.0.

PS:检测IIS是否安装,用HKLM\SOFTWARE\Microsoft\InetStp比较准确,IISADMIN非所有系统都有。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多