Dim iispath As String, setuppath As String, iisname As String iisname = 虚拟目录名称 setuppath = 虚拟目录路径 iispath = setuppath & "\web" Screen.MousePointer = 11 strDefaultDoc = "index.htm" '默认文档名Dim objIISOn Error Resume Next Set objIIS = GetObject("IIS://127.0.0.1/W3SVC/1")If Err.Number = -2147024893 Then MsgBox "IIS不存在!" & vbCrLf & "请验证IIS是否已正确安装!", vbCritical ElseIf Err.Number <> 0 Then MsgBox "未知错误!", vbCritical End IfOn Error GoTo 0Set objVirtualDir = objIIS.GetObject("IISWebVirtualDir", "Root") For Each VR In objVirtualDir If VR.Name = iisname Then tt = MsgBox("虚拟目录<" & iisname & ">已存在,是否清除虚拟目录<" & iisname & ">," & Chr(13) & "并建立新的<" & iisname & ">虚拟目录?", vbOKCancel + vbQuestion, "提示") If tt = vbCancel Then MsgBox "你已取消创建新的虚拟目录<" & iisname & ">, " & Chr(13) & "稍后请手工重新配置IIS!", vbInformation End End If If tt = vbOK Then virdir = objVirtualDir.Delete("IISWebVirtualDir", iisname) End If End If NextOn Error Resume Next Set fs = Wscript.CreateObject("Scripting.FileSystemObject") Set objFolder = fs.GetFolder(iispath)If Err.Number = 76 Then MsgBox "路径" & iispath & "不存在!", vbCritical End IfSet objFolder = Nothing Set fs = Nothing On Error GoTo 0On Error Resume Next Set virdir = objVirtualDir.Create("IISWebVirtualDir", iisname) virdir.AccessRead = True '读取 virdir.AccessWrite = False '写入 virdir.Path = iispath '虚拟目录路径 virdir.DefaultDoc = virdir.DefaultDoc & "," & strDefaultDoc virdir.AccessScript = True '执行许可(纯脚本) 'virdir.AccessExecute = False '执行许可(脚本和可执行程序) virdir.AppRoot = "/LM/W3SVC/1/root/" & iisname virdir.AppFriendlyName = iisname '应用程序名 virdir.AppIsolated = 2 '应用程序保护 0:低 1:高 2:中 'virdir.AccessSource = false '脚本资源访问 'virdir.FrontPageWeb = True 'virdir.EnableDirBrowsing = False '目录游览 'virdir.AccessNoRemoteRead = False 'virdir.AccessNoRemoteWrite = False 'virdir.AccessNoRemoteExecute = False 'virdir.AccessNoRemoteScript = False 'virdir.createprocessasuser = false virdir.setInfoIf Err.Number <> 0 Then MsgBox "创建虚拟目录失败,稍后请手工重新配置IIS!", vbCritical End Else MsgBox "虚拟目录<" & iisname & ">创建成功!", vbInformation End End IfScreen.MousePointer = 0
http://www.codesky.net/article/list.asp?id=5040
' Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service. set locatorObj = CreateObject("WbemScripting.SWbemLocator") set providerObj = locatorObj.ConnectServer(".", "root/MicrosoftIISv2") set serviceObj = providerObj.Get("IIsWebService='W3SVC'")' Build binding object, which is a required parameter of the CreateNewSite method. ' Use the SpawnInstance WMI method since we are creating a new instance of an object. Bindings = Array(0) Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_() Bindings(0).IP = "" Bindings(0).Port = "8383" Bindings(0).Hostname = ""' Create the new Web site using the CreateNewSite method of the IIsWebService object. Dim strSiteObjPath strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\Inetpub\Wwwroot") If Err Then WScript.Echo "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***" WScript.Quit(1) End If' strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907' ' To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object. Set objPath = CreateObject("WbemScripting.SWbemObjectPath") objPath.Path = strSiteObjPath strSitePath = objPath.Keys.Item("")' Set some properties on the root virtual directory which was created by CreateNewSite. Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'") vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous vdirObj.EnableDefaultDoc = True vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate vdirObj.AccessFlags = 513 ' read, script vdirObj.AppFriendlyName = "Root Application"' Save the new settings to the metabase vdirObj.Put_()' CreateNewSite does not start the server, so start it now. Set serverObj = providerObj.Get(strSiteObjPath) serverObj.StartWScript.Echo "A New site called MyNewSite was created with the path and unique site identification number of " & strSitePath
引用:Microsoft WMI Scripting v1.2 libarary Active DS IIS Extension Dll
iisname = 虚拟目录名称
setuppath = 虚拟目录路径
iispath = setuppath & "\web"
Screen.MousePointer = 11
strDefaultDoc = "index.htm" '默认文档名Dim objIISOn Error Resume Next
Set objIIS = GetObject("IIS://127.0.0.1/W3SVC/1")If Err.Number = -2147024893 Then
MsgBox "IIS不存在!" & vbCrLf & "请验证IIS是否已正确安装!", vbCritical
ElseIf Err.Number <> 0 Then
MsgBox "未知错误!", vbCritical
End IfOn Error GoTo 0Set objVirtualDir = objIIS.GetObject("IISWebVirtualDir", "Root")
For Each VR In objVirtualDir
If VR.Name = iisname Then
tt = MsgBox("虚拟目录<" & iisname & ">已存在,是否清除虚拟目录<" & iisname & ">," & Chr(13) & "并建立新的<" & iisname & ">虚拟目录?", vbOKCancel + vbQuestion, "提示")
If tt = vbCancel Then
MsgBox "你已取消创建新的虚拟目录<" & iisname & ">, " & Chr(13) & "稍后请手工重新配置IIS!", vbInformation
End
End If
If tt = vbOK Then
virdir = objVirtualDir.Delete("IISWebVirtualDir", iisname)
End If
End If
NextOn Error Resume Next
Set fs = Wscript.CreateObject("Scripting.FileSystemObject")
Set objFolder = fs.GetFolder(iispath)If Err.Number = 76 Then
MsgBox "路径" & iispath & "不存在!", vbCritical
End IfSet objFolder = Nothing
Set fs = Nothing
On Error GoTo 0On Error Resume Next
Set virdir = objVirtualDir.Create("IISWebVirtualDir", iisname)
virdir.AccessRead = True '读取
virdir.AccessWrite = False '写入
virdir.Path = iispath '虚拟目录路径
virdir.DefaultDoc = virdir.DefaultDoc & "," & strDefaultDoc
virdir.AccessScript = True '执行许可(纯脚本)
'virdir.AccessExecute = False '执行许可(脚本和可执行程序)
virdir.AppRoot = "/LM/W3SVC/1/root/" & iisname
virdir.AppFriendlyName = iisname '应用程序名
virdir.AppIsolated = 2 '应用程序保护 0:低 1:高 2:中
'virdir.AccessSource = false '脚本资源访问
'virdir.FrontPageWeb = True
'virdir.EnableDirBrowsing = False '目录游览
'virdir.AccessNoRemoteRead = False
'virdir.AccessNoRemoteWrite = False
'virdir.AccessNoRemoteExecute = False
'virdir.AccessNoRemoteScript = False
'virdir.createprocessasuser = false
virdir.setInfoIf Err.Number <> 0 Then
MsgBox "创建虚拟目录失败,稍后请手工重新配置IIS!", vbCritical
End
Else
MsgBox "虚拟目录<" & iisname & ">创建成功!", vbInformation
End
End IfScreen.MousePointer = 0
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer(".", "root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")' Build binding object, which is a required parameter of the CreateNewSite method.
' Use the SpawnInstance WMI method since we are creating a new instance of an object.
Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = ""
Bindings(0).Port = "8383"
Bindings(0).Hostname = ""' Create the new Web site using the CreateNewSite method of the IIsWebService object.
Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\Inetpub\Wwwroot")
If Err Then
WScript.Echo "*** Error Creating Site: " & Hex(Err.Number) & ": " & Err.Description & " ***"
WScript.Quit(1)
End If' strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907'
' To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object.
Set objPath = CreateObject("WbemScripting.SWbemObjectPath")
objPath.Path = strSiteObjPath
strSitePath = objPath.Keys.Item("")' Set some properties on the root virtual directory which was created by CreateNewSite.
Set vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" & strSitePath & "/ROOT'")
vdirObj.AuthFlags = 5 ' AuthNTLM + AuthAnonymous
vdirObj.EnableDefaultDoc = True
vdirObj.DirBrowseFlags = &H4000003E ' date, time, size, extension, longdate
vdirObj.AccessFlags = 513 ' read, script
vdirObj.AppFriendlyName = "Root Application"' Save the new settings to the metabase
vdirObj.Put_()' CreateNewSite does not start the server, so start it now.
Set serverObj = providerObj.Get(strSiteObjPath)
serverObj.StartWScript.Echo "A New site called MyNewSite was created with the path and unique site identification number of " & strSitePath
Active DS IIS Extension Dll