Private Sub Command1_Click()
CreateIISWebServer
Label1.Caption = "创建成功"
End Sub
Public Sub CreateIISWebServer()
Dim obj As Object
Dim Web, NewWeb, Child, VirDir As Object
Dim SBinds()
Dim Ip, HostName, IIsInstallPath As String
Ip = "10.143.132.119" 'IP地址
HostName = "www.wanghui.com" '主机头
IIsInstallPath = "d:wwwasp" '目录路径
Dim WebName, i, Port As Integer
WebName = 1
Port = 80 '侦听端口
On Error Resume Next
Err.Clear
Set Web = GetObject("IIS://LocalHost/W3SVC")
Do While Err.Number <> 0
If MsgBox("本服务器的Internet Iformation Server 未启动,请启动后重试。", vbRetryCancel, "IIS服务未启动") = vbCancel Then End
Err.Clear
Set Web = GetObject("IIS://LocalHost/W3SVC")
Loop
Err.Clear
For Each Child In Web
If IsNumeric(Child.Name) Then
If CInt(Child.Name) >= WebName Then WebName = CInt(Child.Name) + 1
End If
Next
Set NewWeb = Web.Create("IIsWebServer", WebName)
NewWeb.servercomment = "站点说明"
NewWeb.KeyType = "IIsWebServer"
ReDim SBinds(0)
SBinds(0) = Ip & ":" & Port & ":" & HostName
NewWeb.ServerBindings = SBinds
NewWeb.accessread = True
NewWeb.frontPageWeb = True
NewWeb.EnableDefaultDoc = True
NewWeb.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"
NewWeb.AccessScript = True
NewWeb.AccessExecute = True
Set VirDir = NewWeb.Create("IIsWebVirtualDir", "Root")
VirDir.Path = IIsInstallPath
VirDir.AppCreate "TRUE"
VirDir.setinfo
NewWeb.setinfo
NewWeb.start
End Sub
[@more@]
CreateIISWebServer
Label1.Caption = "创建成功"
End Sub
Public Sub CreateIISWebServer()
Dim obj As Object
Dim Web, NewWeb, Child, VirDir As Object
Dim SBinds()
Dim Ip, HostName, IIsInstallPath As String
Ip = "10.143.132.119" 'IP地址
HostName = "www.wanghui.com" '主机头
IIsInstallPath = "d:wwwasp" '目录路径
Dim WebName, i, Port As Integer
WebName = 1
Port = 80 '侦听端口
On Error Resume Next
Err.Clear
Set Web = GetObject("IIS://LocalHost/W3SVC")
Do While Err.Number <> 0
If MsgBox("本服务器的Internet Iformation Server 未启动,请启动后重试。", vbRetryCancel, "IIS服务未启动") = vbCancel Then End
Err.Clear
Set Web = GetObject("IIS://LocalHost/W3SVC")
Loop
Err.Clear
For Each Child In Web
If IsNumeric(Child.Name) Then
If CInt(Child.Name) >= WebName Then WebName = CInt(Child.Name) + 1
End If
Next
Set NewWeb = Web.Create("IIsWebServer", WebName)
NewWeb.servercomment = "站点说明"
NewWeb.KeyType = "IIsWebServer"
ReDim SBinds(0)
SBinds(0) = Ip & ":" & Port & ":" & HostName
NewWeb.ServerBindings = SBinds
NewWeb.accessread = True
NewWeb.frontPageWeb = True
NewWeb.EnableDefaultDoc = True
NewWeb.DefaultDoc = "Default.htm, Default.asp, Index.htm, Index.asp"
NewWeb.AccessScript = True
NewWeb.AccessExecute = True
Set VirDir = NewWeb.Create("IIsWebVirtualDir", "Root")
VirDir.Path = IIsInstallPath
VirDir.AppCreate "TRUE"
VirDir.setinfo
NewWeb.setinfo
NewWeb.start
End Sub
[@more@]
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9650775/viewspace-922511/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9650775/viewspace-922511/
本文介绍了一种使用VBA创建IIS网站的方法。通过设置网站名称、监听端口、IP地址、主机头等参数,并定义网站目录路径,可以实现自动化创建IIS网站的目的。
2800

被折叠的 条评论
为什么被折叠?



