读取本地组策略/Active Directory 设置
我正在编写一个 C# 程序,它将根据 Windows 组策略设置“密码必须满足复杂性要求”强制执行密码复杂性。具体来说,如果该策略在本地计算机上(如果它不是域的一部分)或通过域安全策略(对于域成员)设置为启用,则我的软件需要强制执行复杂的密码以确保其自身的内部安全。
问题是我不知道如何读取该 GPO 设置。 Google 搜索表明我可以使用这两个 API 之一读取 GPO 设置:.NET Framework 中的 System.DirectoryServices 库和 Windows Management Instrumentation (WMI),但到目前为止我还没有取得任何成功。
任何见解都会有帮助。
I'm writing a C# program that will enforce password complexity in accordance with the Windows Group Policy setting "Password must meet complexity requirements". Specifically, if that policy is set to Enabled either on the local machine (if it's not part of a domain) or by the Domain Security Policy (for domain members), then my software needs to enforce a complex password for its own internal security.
The issue is that I can't figure out how to read that GPO setting. Google searches have indicated that I can read GPO settings with one of these two APIs: the System.DirectoryServices library in .NET Framework, and Windows Management Instrumentation (WMI), but I haven't had any success so far.
Any insights would be helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎没有针对此任务的记录 API,无论是托管还是其他方式。
托管尝试
我使用 System.Management 程序集尝试了托管路由:
但这不会返回结果。这似乎不是权限问题,因为向
ConnectionOptions
提供用户名/密码对会导致异常,告诉您在本地连接时无法指定用户名。非托管尝试
我查看了 NetUserModalsGet。虽然这将返回有关密码设置的一些信息:
..它不会告诉 密码复杂性策略已启用。
工具输出抓取“成功”
所以我求助于解析 secedit.exe 输出。
完整代码在这里:http://gist.github.com/421802
There doesn't appear to be a documented API for this task, managed or otherwise.
Managed Attempt
I tried the managed route using the System.Management assembly:
This however will not return results. It doesn't appear to be a permission issue as providing a username/password pair to
ConnectionOptions
results in an exception telling you that you can not specify a username when connecting locally.Unmanaged Attempt
I looked at NetUserModalsGet. While this will return some information on password settings:
..it will not let tell if the Password Complexity policy is enabled.
Tool Output Scraping 'Success'
So I resorted to parsing secedit.exe output.
Full code here: http://gist.github.com/421802
您可以使用策略结果集 (RSOP) 工具。例如,这里有一个 VBScript(取自此处),它会告诉您你需要知道什么。将其翻译成 C# 应该很简单。
You can use the Resultant Set of Policy (RSOP) tools. E.g. here's a VBScript (lifted from here) which will tell you what you need to know. It should be simple enough to translate this into C#.
我遇到了您的这个 Microsoft 论坛答案 http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f3f5a61f-2ab9-459e-a1ee-c187465198e0
希望这对将来遇到这个问题的人有所帮助。
I came across your this Microsoft forum answer http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/f3f5a61f-2ab9-459e-a1ee-c187465198e0
Hope this helps somebody who comes across this question in the future.