【发布时间】:2010-01-22 18:25:56
【问题描述】:
我们有一个安装在 Windows 2003 和 Windows 2008 系统上的 Web 应用程序。过去,我们的安装代码使用 ADSI 在 IIS 中创建几个应用程序目录,但这需要在 Windows 2008 中安装 IIS 6 管理组件。我一直在尝试使用 WMI 来创建应用程序目录,因此我们可以支持两种操作系统。
我一直在尝试这段代码
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();
}
}
但是,我在已知目录中发现路径未找到错误。如果有人有一些我可以使用的参考资料,我将不胜感激。也欢迎任何其他关于如何解决此问题的建议。
【问题讨论】: