iis 7 - Use WMI to create IIS Application Directory with C# -
we have web application installed on windows 2003 , windows 2008 systems. in past, our install code used adsi create couple of application directories in iis, requires iis 6 management components installed in windows 2008. have been trying use wmi create application directories can support both operating systems.
i have been trying code
public static void addvirtualfolder(string servername, string websiteid, string name, string path) { managementscope scope = new managementscope(string.format(@"\\{0}\root\microsoftiisv2", servername)); scope.connect(); string sitename = string.format("w3svc/{0}/root/{1}", websiteid, name); managementclass mc = new managementclass(scope, new managementpath("iiswebvirtualdirsetting"), null); managementobject owebvirtdir = mc.createinstance(); owebvirtdir.properties["name"].value = sitename; owebvirtdir.properties["path"].value = path; owebvirtdir.properties["authflags"].value = 5; // integrated windows auth. owebvirtdir.properties["enabledefaultdoc"].value = true; // date, time, size, extension, longdate ; owebvirtdir.properties["dirbrowseflags"].value = 0x4000003e; owebvirtdir.properties["accessflags"].value = 513; // read script owebvirtdir.put(); managementobject mo = new managementobject(scope, new system.management.managementpath("iiswebvirtualdir='" + sitename + "'"), null); managementbaseobject inputparameters = mo.getmethodparameters("appcreate2"); inputparameters["appmode"] = 2; mo.invokemethod("appcreate2", inputparameters, null); mo = new managementobject(scope, new system.management.managementpath("iiswebvirtualdirsetting='" + sitename + "'"), null); mo.properties["appfriendlyname"].value = name; mo.put(); } }
however, path not found errors on known directories. if has references can use, appreciate it. other suggestions on how go welcome.
using code above, still need iis6 compatibility bits on windows 2008/iis7. reason calls set properties such dirbrowseflags
, accessflags
, on iis 6 metabase properties not supported in iis7 without iis6 management components.
for iis7 i'd recommend programming directly against microsoft.web.administration
namespace, if need use wmi see article:
Comments
Post a Comment