« 日有所思,月有所进用VB在SQL中自动附加数据库 »

IIS中自动添加虚拟目录的关键语句

最近在网站下做多个虚拟目录,感觉用手工去做的话,很费劲,于是想到一个办法,用一个程序批量来做如此多重复的工作。于是想到了以下在IIS中自动添多个虚拟目录的办法。

 实现程序自动添加,要知道以下几个变量:

1、虚拟目录的变量 (如:gotest。)

2、主目录的属性参数变量 (如:写入,读取等)

3、默认文档的变量 (如:default.asp)

4、启动父路径 AspEnableParentPaths="TRUE"

通过在网上查询资料,可用如下代码在VB中实现虚拟目录的自动设置。

具体操作参数不明确的话,可用如下方法获取配置参数,如法炮制。

在IIS中首先设置好一个虚拟目录,

[IMG]upload/iis1.jpg[/IMG]

右击虚拟目录,导出配置文件为文本文件。

[IMG]upload/iis2.jpg[/IMG]

 

打开文本文件,查看具体参数。

 Location ="/LM/W3SVC/1/Root/gotest"
  AccessFlags="AccessRead | AccessWrite | AccessScript"
  AppFriendlyName="gotest"
  AppIsolated="0"
  AppRoot="/LM/W3SVC/1/Root/gotest"
  AspEnableParentPaths="TRUE"
  DefaultDoc="default.asp"
  Path="E:\Z-Blog17\"

其中gotest,e:\z-blog17\等是举例,可自定义。

我是用如下代码实现的:

 


 

 Private Sub Command1_Click()

      strWebSite = "gotest"                               '虚拟站点名称
      strFriendlyName = "gotest"                           '程序名称
      strWebPath = "E:\Z-Blog17\"               '网页文件路径
      strDefaultDoc = "default.asp"                                             '默认网站首页
     
  MsgBox WebVirtualDir(strWebSite, strFriendlyName, strWebPath, strDefaultDoc)
 
  End Sub
Public Function WebVirtualDir(ByVal strWebSite As String, ByVal strFriendlyName As String, ByVal strWebPath As String, ByVal strDefaultDoc As String) As Boolean
          Dim Han       As Object
          Dim Coco     As Object
           
          On Error GoTo Wrong_Err

            Set Han = GetObject("IIS://localhost/W3SVC/1/Root")               

            Set Coco = Han.Create("IIsWebVirtualDir", strWebSite)                
                  Coco.SetInfo
              Set Coco = Han.GetObject("IIsWebVirtualDir", strWebSite)
                  Coco.AppCreate True
                  Coco.put "AppFriendlyName", strFriendlyName
                  Coco.put "AppRoot", "/LM/W3SVC/1/Root/" & strWebSite
                  Coco.put "Path", strWebPath
                  Coco.put "AppIsolated", 0

                   Coco.put "DefaultDoc", strDefaultDoc
                  Coco.put "AccessFlags", 515
                  Coco.put "AspEnableParentPaths", True
                  Coco.SetInfo
          WebVirtualDir = True
           
Wrong_End:
          Set Coco = Nothing

            Set Han = Nothing
          Exit Function
 Wrong_Err:
          WebVirtualDir = False

           strError = Err.Description
          Err.Clear
          Resume Wrong_End
           
  End Function

 


 

 如果要在同一服务器的IIS的不同网站中添加虚拟目录,可先通过导出配置文件的方法,获得该网站的编号,然后替换"/LM/W3SVC/1/Root/" 中的“1”就可以啦。

 

  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.7 Laputa Build 70216

版权所有,未经授权禁止转载、摘编、复制或建立镜像.如有违反,追究法律责任
Email: gogansu@gmail.com 陇ICP备08100741号 版权所有:博客骄子网
客服QQ:116545524QQ:116545524 QQ:116545524