vbscript自动配置IIS的代码

所属分类: 脚本专栏 / vbs 阅读数: 391
收藏 0 赞 0 分享
复制代码 代码如下:

strServerName =""localhost""
strRootPath=""g:\documents"" ''虚拟目录路径
strVRName=""Test"" ''虚拟目录名称
strDefaultDoc=""index.asp"" ''起始文档

Dim objIIS
''MsgBox ""IIS://"" &  strServerName &  ""/W3SVC/1""

On Error Resume Next
Set objIIS=GetObject(""IIS://"" &  strServerName &  ""/W3SVC/1"")

If err=-2147024893 Then
MsgBox ""IIS不存在!"" &  vbcrlf &  ""请验证IIS是否已正确安装!"",vbcritical
Wscript.Quit
ElseIf err<>0 Then
MsgBox ""未知错误!"",vbcritical
Wscript.Quit
End If

On Error GoTo 0

Set objVirtualDir=objIIS.GetObject(""IISWebVirtualDir"",""Root"")
For each VR in objVirtualDir
If VR.Name=strVRName Then
MsgBox ""虚拟目录"" &  strVRName &  ""已存在!"",vbinformation
Wscript.Quit
End If
Next

On Error Resume Next
Set fs=Wscript.CreateObject(""Scripting.FileSystemObject"")
Set objFolder=fs.GetFolder(strRootPath)

If err=76 Then 
MsgBox ""路径"" &  strRootPath &  ""不存在!"",vbcritical
Wscript.Quit
End If

Set objFolder=nothing
Set fs=nothing
On Error GoTo 0

On Error Resume Next
Set VirDir=objVirtualDir.Create(""IISWebVirtualDir"",strVRName)
VirDir.AccessRead=true
VirDir.Path=strRootPath
VirDir.DefaultDoc=VirDir.DefaultDoc &  "","" &  strDefaultDoc

VirDir.setInfo

If err<>0 Then
MsgBox ""创建虚拟目录失败!"",vbcritical
Else
MsgBox ""虚拟目录"" &  strVRName &  ""成功创建在服务器"" &  strServerName &  ""上!"",vbinformation
End If

代码的关键在于创建虚拟目录,及其中的配置:

Set VirDir=objVirtualDir.Create(""IISWebVirtualDir"",strVRName)
VirDir.AccessRead=true
VirDir.Path=strRootPath
VirDir.DefaultDoc=VirDir.DefaultDoc &  "","" &  strDefaultDoc

VirDir.setInfo


更多精彩内容其他人还在看

VBS教程:函数-Chr 函数

VBS教程:函数-Chr 函数
收藏 0 赞 0 分享

VBS教程:函数-CDbl 函数

VBS教程:函数-CDbl 函数
收藏 0 赞 0 分享

VBS教程:函数-CDate 函数

VBS教程:函数-CDate 函数
收藏 0 赞 0 分享

VBS教程:函数-CCur 函数

VBS教程:函数-CCur 函数
收藏 0 赞 0 分享

VBS教程:函数-CByte 函数

VBS教程:函数-CByte 函数
收藏 0 赞 0 分享

VBS教程:函数-CBool 函数

VBS教程:函数-CBool 函数
收藏 0 赞 0 分享

VBS教程:函数-Atn 函数

VBS教程:函数-Atn 函数
收藏 0 赞 0 分享

VBS教程:函数-Asc 函数

VBS教程:函数-Asc 函数
收藏 0 赞 0 分享

VBS教程:函数-Array 函数

VBS教程:函数-Array 函数
收藏 0 赞 0 分享

VBS教程:函数-Abs 函数

VBS教程:函数-Abs 函数
收藏 0 赞 0 分享
查看更多