私は悪いディレクトリの日を過ごしています。:)
誰かがこれの何が悪いのか教えてもらえますか?
groupName = "Monkey";
...
using (DirectoryEntry directoryEntryObject = new DirectoryEntry("WinNT://" + Environment.MachineName, "", "", AuthenticationTypes.Secure))
{
using (DirectoryEntry group = directoryEntryObject.Children.Add("CN=" + groupName.Trim(), "group"))
{
group.Properties["sAMAccountName"].Value = groupName;
group.CommitChanges();
}
}
私がやろうとしているのは、ローカルアカウントを作成することです。このコードをそのまま試すと、samaccountname プロパティを設定しようとするとクラッシュします。
System.Runtime.InteropServices.COMException occurred
Message="The directory property cannot be found in the cache.\r\n"
Source="Active Directory"
ErrorCode=-2147463153
StackTrace:
at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.PutEx(Int32 lnControlCode, String bstrName, Object vProp)
InnerException:
その行をコメントアウトすると、コミット時に次のようにクラッシュします。
System.Runtime.InteropServices.COMException occurred
Message="The specified username is invalid. (Exception from HRESULT: 0x8007089A)"
Source="System.DirectoryServices"
ErrorCode=-2147022694
StackTrace:
at System.DirectoryServices.Interop.UnsafeNativeMethods.IAds.SetInfo()
InnerException:
ソースについてどう考えるべきかわかりません。W2003 ドメインの Vista を使用していますが、Active Directory グループではなく、ローカル グループを作成しようとしています。
何か案は?私はおそらく明らかな何かを見逃しました。GroupPricipal.Save メソッドを使用してユーザーを作成できるので、権限の問題ではありません。