InstallShield 通过VBS操作IIS

最近在做覆盖安装,不同安装包文件卸载时可以完美删除,只有Webservice不会删除,后来在帮助文档中发现这么一句话:

If a Web site already exists, Virtual Directories tied to that Web site in the project will be installed under that Web site. However, none of the properties set for that Web site in the InstallShield interface will be applied to the Web site in that case.

既然这样,干脆自己用脚本删除对应的Webservice。

Installshield 2009 , Installscript Project 工程

首先建立一个脚本:

在此脚本文件内编写一下脚本:

Code
 1 //////////////////////////////////////////////////////////////////////
 2 // InstallScript 设置 IIS 脚本
 3 // 主要功能:通过使用VBS 查找、创建、更改、删除站点,
 4 //                         查找、创建、更改、删除虚拟目录           
 5 
 6 //prototype FindWebSite(STRING,STRING,NUMBER); 
 7 prototype FindWebVirtualDir(string);
 8 prototype DelWebVirtualDir(string);       
 9 
10 //*********************************************************
11 //** FindWebVirtualDir  检查Webservice是否存在
12 //** @param string      要查找的Webservice名称   
13 //** @return            1 找到了指定的webservice;
14 //**                       0 未找到指定的Webservice;                   
15 //*********************************************************        
16 function FindWebVirtualDir(strVirtualDirectoryName)    
17 object objIIS,objVirtualDirectory; 
18 number nvReturn;
19 begin
20      set  objIIS=CoGetObject("IIS://localhost/W3SVC/1/Root","");    
21      if(IsObject(objIIS)) then   
22          try
23           set objVirtualDirectory = objIIS.Create("IISWebVirtualDir",strVirtualDirectoryName); 
24           nvReturn=0;
25         catch
26           nvReturn=1;
27         endcatch; 
28      endif;
29      return nvReturn;
30 end;   
31 //*********************************************************
32 //** DelWebVirtualDir   删除指定的Webservice
33 //** @param string      要删除的Webservice名称   
34 //** @return            1 删除成功;
35 //**                       0 未删除成功;                   
36 //*********************************************************  
37 function  DelWebVirtualDir(strVirtualDirectoryName)
38 object objIIS,objVirtualDirectory; 
39 number nvReturn;
40 begin
41      set  objIIS=CoGetObject("IIS://localhost/W3SVC/1/Root","");    
42      if(IsObject(objIIS)) then   
43          try      
44           set objVirtualDirectory = objIIS.GetObject("IISWebVirtualDir",strVirtualDirectoryName);
45           if(IsObject(objVirtualDirectory)) then
46               objIIS.Delete("IIsObject",strVirtualDirectoryName);
47                 nvReturn=1; 
48           endif;   
49         catch
50           nvReturn=0;
51         endcatch; 
52      endif;
53      return nvReturn;
54 end;

此脚本只是个例子,剩余功能填充即可。

在Setup.Rul中调用函数:

http://www.cnblogs.com/HeroBeast/archive/2009/03/06/1404791.html处学习,很全面

posted @ 2013-03-28 15:49  竹林逸轩  阅读(463)  评论(0编辑  收藏  举报