日期:2009-03-18  浏览次数:20458 次

原先我是不知道的,在网上也是一直找不到相关资料,后来无意间在一个delphi版的 介绍中看到了相关的内容,于是用vb仿做了一个。
如果也有人无意间看到受益,则大感欣慰也。


基础:添加以下引用:1,iisext.dll; 2, adsiis.dll; 3,activeds.tlb。

1,在 IIS 建立虚拟目录,
Dim sComputer as string
Dim websvc, vRoot, vDir
sComputer = "localhost"

'Get Default Web Site Object
Set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")

'Get root of Default Web Site
Set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")

Dim itm As ListItem
Dim buf As String, errInfo As String, tryVirt
For Each itm In ListView1.ListItems
Err.Clear
On Error Resume Next
Set tryVirt = GetObject("IIS://" & sComputer & "/W3svc/1/ROOT/" & itm.SubItems(1))
'Debug.Print Err.Number
'如果得不到对应的虚拟目录,则出错,此时可以新建此虚拟目录。
If Err.Number <> 0 Then
Err.Clear
Set vDir = vRoot.Create("IISWebVirtualDir", itm.SubItems(1))
vDir.path = itm.Text
vDir.Accessread = True
vDir.SetInfo

Else
'记录已经创建的虚拟目录名称。
'If tryVirt.AppGetStatus2 = 0 Then
errInfo = errInfo & vbCrLf & itm.SubItems(1)
End If

Next

其实就是
Set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")
Set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")
Set vDir = vRoot.Create("IISWebVirtualDir", vdName)
vDir.Path=someDir
vDir.setInfo
这几个语句就够了

2。删除虚拟目录
Dim sComputer, sPhyDir, sVirDir As String
Dim websvc, vRoot, vDir
sComputer = "localhost"

'Get Default Web Site Object
Set websvc = GetObject("IIS://" & sComputer & "/W3svc/1")

'Get root of Default Web Site
Set vRoot = websvc.GetObject("IIsWebVirtualDir", "Root")

Dim itm As ListItem
Dim buf As String, errInfo As String, tryVirt
For Each itm In ListView1.ListItems
Err.Clear
On Error Resume Next
Call vRoot.Delete("IISWebVirtualDir", itm.SubItems(1))
If Err.Number <> 0 Then
errInfo = errInfo & vbCrLf & itm.SubItems(1)
End If
Err.Clear
Next