使用VB对IIS进行简单的管理

使用VB对IIS进行简单的管理,第1张

概述'建立活动桌面'(IADS)对象,首先要引用 Active DS Type library 组件 Dim WWWServer As IADs, WWWService As IADs, WWWVDir, WWWVdirRes As IADs Function CreateWebSite(ByVal WWWSiteName As String, _     ByVal WWWSitePort As S

'建立活动桌面'(IADS)对象,首先要引用 Active DS Type library 组件
Dim WWWServer As IADs,WWWService As IADs,WWWVDir,WWWVdirRes As IADs

Function CreateWebSite(ByVal WWWSitename As String,_
ByVal WWWSitePort As String,_
ByVal WWWSitePath As String,_
ByVal WWWHostname As String,_
ByVal Computername As String) As Boolean
'变量定义
Dim SiteExist As Boolean
Dim Webname

'变量初始化
SiteExist = False
Webname = 1
CreateWebSite = True
On Error Resume Next
Err.Clear
'取得W3SVC服务
Set WWWService = Getobject("IIS://" & Computername & "/W3SVC")
do while Err.Number <> 0
Err.Clear
Set WWWService = Getobject("IIS://" & Computername & "/W3SVC")
Loop
Err.Clear
'出错处理
'在IIS中查找每一个WEB站点
For Each WWWServer In WWWService
If UCase(Trim(WWWServer.ServerComment)) <> UCase(Trim(WWWSitename)) Then
If IsNumeric(WWWServer.name) Then
If CInt(WWWServer.name) >= Webname Then Webname = CInt(WWWServer.name) + 1
End If
Else
SiteExist = True
Exit For
End If
Next
If SiteExist Then
MsgBox "该站点已经存在!",vbinformation + vbOKOnly,"系统信息"
Exit Function
End If
'创建WebServer
Set WWWServer = WWWService.Create("IISWebServer",Webname) '创建新站点
WWWServer.ServerComment = WWWSitename '设置站点名
WWWServer.KeyType = "IISWebServer"
WWWServer.ServerBindings = ":" & WWWSitePort & ":" & WWWHostname '设置端口号和主机头
WWWServer.DefaultDoc = "Default.asp,Index.asp,Default.htm,Index.htm" '设置默认启动文件
WWWServer.AccessScript = True '设置权限
WWWServer.AccessRead = True
WWWServer.FrontPageWeb = True
WWWServer.EnableDefaultDoc = True
WWWServer.DefaultDoc = "Default.htm,Default.asp,Index.htm,Index.asp"
Set WWWVDir = WWWServer.Create("IISWebVirtualDir","Root")
WWWVDir.Path = WWWSitePath
WWWVDir.AppCreate True
WWWVDir.SetInfo
WWWServer.SetInfo
WWWServer.Start
MsgBox "主机设置成功!","系统信息"

'Set WWWVdirRes = WWWVdir.Create("IISWebVirtualDir","Resource") '创建虚拟目录
'WWWVdirRes.Path = WWWfilesPath + "/Resource"
'WWWVdirRes.AccessRead = True
'WWWVdirRes.AccessWrite = True
'WWWVdirRes.SetInfo
'下面为自定义IIS Web Server的错误信息,等发生404错误时候指定调用网站主目录下的404.htm页面显示
'WWWServer.httpErrors = "404,file," + WWWfilesPath + "/404.htm"
'WWWServer.SetInfo
CreateWebSite = True
End Function

Function DeleteWebSite(ByVal WWWSitename As String,ByVal Computername As String) As Boolean
'定义变量
Dim Tmp As Integer
Dim Webname
Dim SiteExist As Boolean
'变量初始化
SiteExist = False
DeleteWebSite = True
'取得W3SVC服务
On Error Resume Next
Err.Clear
Set WWWService = Getobject("IIS://" & Computername & "/W3SVC")
do while Err.Number <> 0
Err.Clear
Set WWWService = Getobject("IIS://" & Computername & "/W3SVC")
Loop
Err.Clear
For Each WWWServer In WWWService
If UCase(Trim(WWWServer.ServerComment)) <> UCase(Trim(WWWSitename)) Then
SiteExist = False
Else
If IsNumeric(WWWServer.name) Then
Webname = WWWServer.name
End If
SiteExist = True
Exit For
End If
Next
'删除站点
WWWService.Delete "IISWebServer",Webname
MsgBox "主机删除成功!","系统信息"
End Function

Private Sub cmdCreateWebSite_Click()
CreateWebSite txtSitename.Text,txtSitePort.Text,txtSitePath.Text,txtHostname.Text,txtComputername.Text
End Sub

Private Sub cmdDeleteWebSite_Click() DeleteWebSite txtSitename.Text,txtComputername.Text End Sub

总结

以上是内存溢出为你收集整理的使用VB对IIS进行简单的管理全部内容,希望文章能够帮你解决使用VB对IIS进行简单的管理所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1284843.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存