// Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
var locatorObj = new ActiveXObject("WbemScripting.SWbemLocator");
var providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2");
var 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.
var Bindings = new Array();
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.
try {
var strSiteObjPath;
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings, "C:\\Inetpub\\Wwwroot");
}
catch(e) {
WScript.Echo("*** Error Creating Site: " + e + " " + e.Number + ", " + e.Description + " ***");
WScript.Quit(1);
}
// strSiteObjPath is in the format of IIsWebServer='W3SVC/1180970907'
// To parse out the absolute path, W3SVC/1180970907, use the SWbemObjectPath WMI object.
var objPath = new ActiveXObject("WbemScripting.SWbemObjectPath");
objPath.Path = strSiteObjPath;
strSitePath = objPath.Keys.Item("");
// var some properties on the root virtual directory which was created by CreateNewSite.
var vdirObj = providerObj.Get("IIsWebVirtualDirSetting='" + strSitePath + "/ROOT'");
vdirObj.AuthFlags = 5; // AuthNTLM + AuthAnonymous
vdirObj.EnableDefaultDoc = true;
vdirObj.DirBrowseFlags = 0x4000003E; // 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.
var serverObj = providerObj.Get(strSiteObjPath);
serverObj.Start;
WScript.Echo("A New site called MyNewSite was created with the path and unique site identification
Public Function WebVirtualDir(ByVal strWebSite As String, ByVal strFriendlyName As String, ByVal strWebPath As String, ByVal strDefaultDoc As String) As Boolean
Dim objADSI As Object
Dim objWebVDir As Object
On Error GoTo Lib_Err
Set objADSI = GetObject("IIS://LocalHost/W3SVC/1/Root")
Set objWebVDir = objADSI.Create("IIsWebVirtualDir", strWebSite)
objWebVDir.SetInfo
Up 关注ing...
---------------------------------------------------------------
我知道了,代码如下:
Function DeleteWebsite(ByVal IISPath As String) As Boolean
Dim DirObj
Dim ObjectParam As String
On Error GoTo errs
'IISpath格式为:IIS://机器名/W3SVC/虚拟站点号/ROOT/虚拟目录
If IISPath = "" Then Exit Function
DeleteWebsite = True
ObjectParam = SplitParam(IISPath)
If UCase(ObjectParam) = "ROOT" Then ObjectParam = SplitParam(IISPath) '如果是虚拟站点,那么IIS路径应该再退到上一层
Set DirObj = GetObject(IISPath)
DirObj.Delete "IIsObject", ObjectParam
Exit Function
errs:
If err.Number <> 462 Then
MsgBox "您的系统上可能没有安装IIS或IIS已经破坏!" & Chr(13) & Chr(10) & _
"错误号【" & err.Description & "】", vbOKOnly + vbExclamation, "系统错误"
DeleteWebsite = False
End If
End Function
Function SplitParam(ObjectPath)
' Note: Assume the string has been sanitized (no leading or trailing slashes)
On Error Resume Next
Dim SlashIndex
Dim TempParam
Dim ObjectPathLen
SplitParam = "" ' Assume no parameter
ObjectPathLen = Len(ObjectPath)
' Separate the path of the node from the parameter
SlashIndex = InStrRev(ObjectPath, "/")
If (SlashIndex = 0) Or (SlashIndex = ObjectPathLen) Then
TempParam = ObjectPath
ObjectPath = "" ' ObjectParameter is more important
Else
TempParam = ObjectPath
ObjectPath = Left(ObjectPath, SlashIndex - 1)
TempParam = Right(TempParam, Len(TempParam) - SlashIndex)
End If