ManagementScope scope = new ManagementScope("root/MicrosoftIISv2");
//подключаемся...
scope.Connect();
// выбираем класс
ManagementClass iis = new ManagementClass(
scope,
new ManagementPath("IIsWebService"),
null);
// получаем входные параметры
ManagementBaseObject inParams = iis.GetMethodParameters("CreateNewSite");
// это не важно
inParams.Properties["PathOfRootVirtualDir"].Value="d:\\web\\1";
inParams.Properties["ServerComment"].Value="d:\\web\\1";
// вот здесь проблема...
inParams.Properties["ServerBindings"].Value=;
// Выполняем метод
ManagementBaseObject outParams = iis.InvokeMethod ("CreateNewSite", inParams, null);
Проблема, что подсунуть как значение? "ServerBindings" имеет
свойство isArray в true. т.е. как бы массивчик... в msdn
говориться что это массив из записей класса ServerBindings... если
пытаться в тупую string[] b=new string[3]; не пролазит...
подсовываем просто string b=":80:" тоже самое....
Может кто-нибудь что-нибудь присоветует?
Скрипт на VB по этому поводу:
' Make connections to WMI, to the IIS namespace on MyMachine, and to the Web service.
set locatorObj = CreateObject("WbemScripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer("MyMachine", "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")