我正在寻找一种如何以编程方式创建本地用户组的方法。我发现了很多关于如何查询和添加用户的示例,但我对如何创建新组一无所知。
var dirEntry = new DirectoryEntry(
"WinNT://" + Environment.MachineName + ",computer");
/* Code to test if the group already exists */
if (!found)
{
DirectoryEntry grp = dirEntry.Children.Add(groupName, "Group");
dirEntry.CommitChanges();
}
这就是我所达到的,但我知道这是错误的,因为CommitChanges()
只是抛出一个NotImplementedException
.
我一直在使用它作为示例,但我什至无法让它工作(感谢 MS):
http://msdn.microsoft.com/en-us/library/ms815734
有人有我可以用来创建新本地组的代码片段吗?