ADSI类,控制IIS
作者:佚名 时间:2012-04-13
三年前写的一个ADSI类,控制IIS的,现在拿出来和大家分享吧
今天整理硬盘的时候发现这个可能对大家还比较有用
现在没时间完善了,不然你一定可以做个比蓝芒更牛的虚拟主机管理系统
关于SERV-U的密码其实就是MD5的前两位在动态相加
MS SQL有添加用户和数据库的组件,直接调用就行
企业邮局你可以用WebEasyMail,ASP开发的,兼容性好嘛,呵呵
想提高运行效率就用VB编译成DLL组件吧
作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
<%
Class IISManager
Private strServerName '服务器名称
Private intIndex '站点序号(ID号)
Private strServerComment '站点说明
Private strServerBindings '站点主机头
Private strPath '站点目录路径
Private strDefaultDoc '默认文档
Private intMaxConnections '最大连接数
Private intServerSize '站点性能,0-低(小于10000),1-中(小于100000),2-高(超过100000
)
Private intMaxBandwidth '网络带宽最大使用量,单位(KB) ,-1表示不限制
Private intConnectionTimeout '连接超时秒数,单位(秒)
Private isEnableDefaultDoc '
Private isAccessRead '允许读
Private isAccessWrite '允许写
Private isEnableDirBrowsing '允许目录浏览
Private isAccessScript '执行许可
Private isAccessSource '允许脚本访问
Private isAccessExecute '允许执行应用程序
Private isScriptErrorSentToBrowser '发生错误时,是否发送自定信息到客户端
Private strScriptErrorMessage '发生错误时发给客户端的信息
Private intSessionTimeout 'Session过期时间,单位(分钟)
'构造函数
Sub Class_Initialize()
strServerName = "localhost"
intIndex = 1
strServerComment = "新建站点"
strServerBindings=":80:"
strPath = "c:\inetpub\wwwroot"
strDefaultDoc = "default.htm,default.asp,index.htm,index.asp"
intMaxConnections = 50
intServerSize = 1
intMaxBandwidth = -1
intConnectionTimeout = 600
isEnableDefaultDoc = true
isAccessRead = true
isAccessWrite = false
isEnableDirBrowsing = false
isAccessScript = false
isAccessSource = false
isAccessExecute = false
isScriptErrorSentToBrowser = false
strScriptErrorMessage = "处理 URL 时服务器上出错。请和系统管理员联络。"
intSessionTimeout = 20
End Sub
'定义属性
'-----------------------------------------------
Public Property Let ServerName(strValue)
strServerName=strValue
End Property
Public Property Get ServerName
ServerName=strServerName
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let SiteIndex(intValue)
intIndex=intValue
End Property
Public Property Get SiteIndex
SiteIndex=intIndex
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let ServerComment(strValue)
strServerComment=strValue
End Property
Public Property Get ServerComment
ServerComment=strServerComment
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let ServerBindings(strValue)
strServerBindings=strValue
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let RootPath(strValue)
strPath=strValue
End Property
Public Property Get RootPath
RootPath=strPath
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let DefaultDoc(strValue)
strDefaultDoc=strValue
End Property
Public Property Get DefaultDoc
DefaultDoc=strDefaultDoc
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let MaxConnections(strValue)
intMaxConnections=strValue
End Property
Public Property Get MaxConnections
MaxConnections=intMaxConnections
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let ServerSize(strValue)
intServerSize=strValue
End Property
Public Property Get ServerSize
ServerSize=intServerSize
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Get MaxBandwidth
MaxBandwidth=intMaxBandwidth
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let ServerConnectionTimeout(strValue)
intConnectionTimeout=strValue
End Property
Public Property Get ServerConnectionTimeout
ServerConnectionTimeout=intConnectionTimeout
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let EnableDefaultDoc(boolValue)
isEnableDefaultDoc=boolValue
End Property
Public Property Get EnableDefaultDoc
EnableDefaultDoc=isEnableDefaultDoc
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let AccessRead(boolValue)
isAccessRead=boolValue
End Property
Public Property Get AccessRead
AccessRead=isAccessRead
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let AccessWrite(boolValue)
isAccessWrite=boolValue
End Property
Public Property Get AccessWrite
AccessWrite=isAccessWrite
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let EnableDirBrowsing(boolValue)
isEnableDirBrowsing=boolValue
End Property
Public Property Get EnableDirBrowsing
EnableDirBrowsing=isEnableDirBrowsing
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let AccessScript(boolValue)
isAccessScript=boolValue
End Property
Public Property Get AccessScript
AccessScript=isAccessScript
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let AccessSource(boolValue)
isAccessSource=boolValue
End Property
Public Property Get AccessSource
AccessSource=isAccessSource
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Let AccessExecute(boolValue)
isAccessExecute=boolValue
End Property
Public Property Get AccessExecute
AccessExecute=isAccessExecute
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Get ScriptErrorSentToBrowser
ScriptErrorSentToBrowser=isScriptErrorSentToBrowser
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Get ScriptErrorMessage
ScriptErrorMessage=strScriptErrorMessage
End Property
'-----------------------------------------------
'-----------------------------------------------
Public Property Get SessionTimeout
SessionTimeout=intSessionTimeout
End Property
'-----------------------------------------------
'****************************************************************************
'定义方法/过程/函数
'****************************************************************************
'----------------------------------------------------------------------------
'# 函数:DelWebSite()
'# 描述:删除指定的站点
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function DelWebSite()
On Error Resume Next
Set WWWService = GetObject("IIS://" & strServerName & "/W3SVC")
WWWService.Delete "IISWebServer", Siteindex
If (Err.Number <> 0) Then' 是否出错
DelWebSite = "无法删除站点,错误码:" & Err.Number
Exit Function
End If
DelWebSite = 0
End Function
'----------------------------------------------------------------------------
'# 函数:CreateWebSite()
'# 描述:创建WEB站点
'# 返回:成功返回此站点Index,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function CreateWebSite()
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Dim wNumber '新WEB站点Index
WNumber=1
Do While IsObject(ServiceObj.GetObject("IIsWebServer",WNumber))
If Err.number<>0 Then
Err.Clear()
Exit Do
End If
WNumber=WNumber+1
Loop
Set WebSiteObj = ServiceObj.Create("IIsWebServer", WNumber)' 然后创建一个WEB服务器
If (Err.Number <> 0) Then' 是否出错
CreateWebSite = "错误: 创建Web服务器的ADSI操作失败,原因可能是操作没有获得操作权限或者IIS5.0已经损坏
!"
Exit Function
End If
'接着配置服务器
WebSiteObj.ServerComment = strServerComment
arrServerBindings = Array(0)
arrServerBindings(0)=strServerBindings
WebSiteObj.ServerBindings = arrServerBindings
WebSiteObj.ServerSize = intServerSize
WebSiteObj.MaxConnections = intMaxConnections
WebSiteObj.ConnectionTimeout = intConnectionTimeout
WebSiteObj.EnableDefaultDoc = isEnableDefaultDoc
WebSiteObj.DefaultDoc = strDefaultDoc
WebSiteObj.ServerState = 2
' 提交信息
WebSiteObj.SetInfo
' 最后,建立虚拟目录
Set VDirObj = WebSiteObj.Create("IIsWebVirtualDir", "ROOT")
If (Err.Number <> 0) Then' 是否出错
CreateWebSite= "错误: 创建虚拟目录的ADSI操作失败!"
Exit Function
End If
' 配置虚拟目录
VDirObj.Path = strPath
VDirObj.MaxBandwidth = intMaxBandwidth
VDirObj.SessionTimeout = intSessionTimeout
DirObj.ScriptErrorSentToBrowser = isScriptErrorSentToBrowser
VDirObj.ScriptErrorMessage= strScriptErrorMessage
VDirObj.AccessRead = isAccessRead
VDirObj.AccessWrite = isAccessWrite
VDirObj.EnableDirBrowsing = isEnableDirBrowsing
VDirObj.EnableDefaultDoc = isEnableDefaultDoc
VDirObj.AccessScript=isAccessScript
VDirObj.AccessSource=isAccessSource
VDirObj.AccessExecute=isAccessExecute
VDirObj.AppCreate = 2
VDirObj.AppFriendlyName="默认应用程序"
VDirObj.SetInfo
'WebSiteObj.Start
'If (Err.Number <> 0) Then ' Error!
'CreateWebSite = "错误: 站点已经创建,但无法自动启动,请人工启动!"
'Err.Clear()
'Exit Function
'End If
Set VDirObj=Nothing
Set ServerObj=Nothing
Set ServiceObj=Nothing
CreateWebSite=wNumber
End Function
'----------------------------------------------------------------------------
'# 函数:UpdateWebSite()
'# 描述:修改指定的站点
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function UpdateWebSite()
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Set WebSiteObj=ServiceObj.GetObject("IIsWebServer",intIndex)
If (Err.Number <> 0) Then' 是否出错
UpdateWebSite = "错误: 打开WEB站点失败!"
Exit Function
End If
'修改站点属性
'----------------------------------------------
WebSiteObj.ServerComment = strServerComment
WebSiteObj.ServerSize = intServerSize
WebSiteObj.MaxConnections = intMaxConnections
WebSiteObj.ConnectionTimeout = intConnectionTimeout
WebSiteObj.EnableDefaultDoc = isEnableDefaultDoc
WebSiteObj.DefaultDoc = strDefaultDoc
' 提交信息
WebSiteObj.SetInfo
If (Err.Number <> 0) Then' 是否出错
UpdateWebSite = "错误: 修改WEB站点失败,请检查属性设置是否正确!"
Exit Function
End If
Set VDirObj = WebSiteObj.GetObject("IIsWebVirtualDir", "ROOT")
If (Err.Number <> 0) Then' 是否出错
UpdateWebSite = "错误: WEB站点可能已经损坏,无法进行操作!"
Exit Function
End If
' 配置虚拟目录
VDirObj.Path = strPath
VDirObj.AccessRead = isAccessRead
VDirObj.AccessWrite = isAccessWrite
VDirObj.EnableDirBrowsing = isEnableDirBrowsing
VDirObj.EnableDefaultDoc = isEnableDefaultDoc
VDirObj.AccessScript=isAccessScript
VDirObj.AccessSource=isAccessSource
VDirObj.AccessExecute=isAccessExecute
VDirObj.SetInfo
If (Err.Number <> 0) Then' 是否出错
UpdateWebSite = "错误: 修改WEB目录配置失败,请检查属性设置是否正确!"
Exit Function
End If
Set ServiceObj=nothing
Set WebSiteObj=Nothing
UpdateWebSite=0
End Function
'----------------------------------------------------------------------------
'# 函数:GetInfo()
'# 描述:取出站点属性
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function GetInfo(test)
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Set WebSiteObj=ServiceObj.GetObject("IIsWebServer",test)
If (Err.Number <> 0) Then' 是否出错
GetInfo = "错误: 打开WEB站点失败!"
Exit Function
End If
'取出站点属性
WebSiteObj.GetInfo
strServerComment = WebSiteObj.ServerComment
intServerSize = WebSiteObj.ServerSize
intMaxConnections = WebSiteObj.MaxConnections
intConnectionTimeout = WebSiteObj.ConnectionTimeout
isEnableDefaultDoc = WebSiteObj.EnableDefaultDoc
strDefaultDoc = WebSiteObj.DefaultDoc
Set VDirObj = WebSiteObj.GetObject("IIsWebVirtualDir", "ROOT")
If (Err.Number <> 0) Then' 是否出错
GetInfo = "错误: WEB站点可能已经损坏,无法进行操作!"
Exit Function
End If
'获取目录属性
VDirObj.GetInfo
strPath = VDirObj.Path
'reponse.write strpath
intMaxBandwidth = VDirObj.MaxBandwidth
'reponse.write intMaxBandwidth
intSessionTimeout = VDirObj.SessionTimeout
isScriptErrorSentToBrowser = VDirObj.ScriptErrorSentToBrowser
strScriptErrorMessage = VDirObj.ScriptErrorMessage
isAccessRead = VDirObj.AccessRead
isAccessWrite = VDirObj.AccessWrite
isEnableDirBrowsing = VDirObj.EnableDirBrowsing
isEnableDefaultDoc = VDirObj.EnableDefaultDoc
isAccessScript = VDirObj.AccessScript
isAccessSource = VDirObj.AccessSource
isAccessExecute = VDirObj.AccessExecute
Set ServiceObj=nothing
Set WebSiteObj=Nothing
Set VDirObj=Nothing
GetInfo = 0
End Function
'----------------------------------------------------------------------------
'# 函数:SetHostHeader()
'# 描述:设置主机头
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function SetHostHeader(strHostHeader)
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Set WebSiteObj=ServiceObj.GetObject("IIsWebServer",intIndex)
If (Err.Number <> 0) Then' 是否出错
SetHostHeader = "错误: 打开WEB站点失败!"
Exit Function
End If
arrServerBindings = Array(0)
arrServerBindings(0)=strHostHeader
WebSiteObj.ServerBindings = arrServerBindings
' 提交信息
WebSiteObj.SetInfo
If (Err.Number <> 0) Then' 是否出错
SetHostHeader = "错误: 设置主机头失败,请检查属性设置是否正确!"
Exit Function
End If
Set ServiceObj=nothing
Set WebSiteObj=Nothing
SetHostHeader = 0
End Function
'----------------------------------------------------------------------------
'# 函数:StopWebSite()
'# 描述:停止指定的站点
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function StopWebSite()
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Set WebSiteObj=ServiceObj.GetObject("IIsWebServer",intIndex)
If (Err.Number <> 0) Then' 是否出错
StopWebSite = "错误: 打开WEB站点失败!"
Exit Function
End If
'停止站点
'----------------------------------------------
WebSiteObj.ServerState = 4
' 提交信息
WebSiteObj.SetInfo
If (Err.Number <> 0) Then' 是否出错
StopWebSite = "错误: 无法停止站点!"
Exit Function
End If
Set ServiceObj=nothing
Set WebSiteObj=Nothing
StopWebSite=0
End Function
'----------------------------------------------------------------------------
'# 函数:StartWebSite()
'# 描述:停止指定的站点
'# 返回:成功返回0,失败返回错误码
'# 作者:沈家峰 QQ:5959344 MSN:bigbird998@hotmail.com 有外包项目请找我,C#/asp.net/asp+MS SQL/oracle/access/XML/TXT都可以
'# 日期:2004.10.19
'----------------------------------------------------------------------------
Public Function StartWebSite()
On Error Resume Next
Dim ServiceObj,WebSiteObj,VDirObj
Set ServiceObj = GetObject("IIS://" & strServerName & "/W3SVC")' 首先创建一个服务实例
Set WebSiteObj=ServiceObj.GetObject("IIsWebServer",intIndex)
If (Err.Number <> 0) Then' 是否出错
StartWebSite = "错误: 打开WEB站点失败!"
Exit Function
End If
'停止站点
'----------------------------------------------
WebSiteObj.ServerState = 2
' 提交信息
WebSiteObj.SetInfo
If (Err.Number <> 0) Then' 是否出错
StartWebSite = "错误: 无法停止站点!"
Exit Function
End If
Set ServiceObj=nothing
Set WebSiteObj=Nothing
StartWebSite=0
End Function
End Class
%>
<%
Dim objIISManager
Set objIISManager=new IISManager
a=GetInfo(9)
response.write a
'创建站点
objIISManager.ServerName="localhost"
objIISManager.ServerBindings="192.168.0.1:8004:www.jnnic.com" '格式--IP地址:端口号:域名
response.write objIISManager.CreateWebSite()
'读站点信息
'objIISManager.SiteIndex=50
'objIISManager.GetInfo()
'response.write objIISManager.SiteIndex
'修改站点
'objIISManager.SiteIndex=3
'objIISManager.GetInfo()
'objIISManager.RootPath="g:\temp\IIS"
'response.write objIISManager.UpdateWebSite()
'修改主机头
'response.write objIISManager.SetHostHeader("192.168.1.34:80:jnnic.com")
'停止站点
'response.write objIISManager.StopWebSite()
'启动站点
'response.write objIISManager.StartWebSite()
%>