创建本地用户
我的目录日很糟糕。 :)
有人能告诉我这有什么问题吗?
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 方法创建用户,因此这不是权限问题。
I am having a bad directory day. :)
Could someone tell me what is wrong with this?
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();
}
}
What i am trying to do is create a local account. When I try this code as is, it crashes when I try to set the samaccountname property:
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:
If I comment out that line, it crashes on commit with the following:
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:
I am not sure what to think about the Source. I am on a Vista in a W2003 domain, but I'm trying to create a local group, not an active directory group.
Any ideas? I probably missed something obvious. I can create users using the GroupPricipal.Save method, so it is not a permissions issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试此代码,我很确定它会成功;)
Try this code, I'm pretty sure it will do the trick ;)