我想从元数据库中删除 IIS 的特定属性。谁能帮帮我吗?我们如何使用 C# 中的 DirectoryEntry 类来做到这一点?
问问题
966 次
1 回答
0
使用 MSDN 中的以下代码示例
using System;
using System.DirectoryServices;
class MyClass1
{
static void Main()
{
try
{
String strPath = "IIS://localhost/W3SVC/1/Root";
String strName = "";
// Create a new 'DirectoryEntry' with the given path.
DirectoryEntry myDE = new DirectoryEntry(strPath);
DirectoryEntries myEntries = myDE.Children;
// Create a new entry 'Sample' in the container.
DirectoryEntry myDirectoryEntry =
myEntries.Add("Sample", myDE.SchemaClassName);
// Save changes of entry in the 'Active Directory'.
myDirectoryEntry.CommitChanges();
Console.WriteLine (myDirectoryEntry.Name +
" entry is created in container.");
// Find 'Sample' entry in container.
myDirectoryEntry = myEntries.Find("Sample", myDE.SchemaClassName);
Console.WriteLine(myDirectoryEntry.Name + " found in container.");
// Remove 'Sample' entry from container.
strName = myDirectoryEntry.Name;
myEntries.Remove(myDirectoryEntry);
Console.WriteLine(strName+ " entry is removed from container.");
}
catch(Exception e)
{
Console.WriteLine("The following exception was raised : {0}",
e.Message);
}
}
}
于 2010-03-18T09:27:08.813 回答