简体   繁体   English

如何使用 c# 配置密码策略(组策略)

[英]How can I configure Password Policy(Group Policy) using c#

How can I configure Password policy in windows using group policy in c#.如何使用 c# 中的组策略在 windows 中配置密码策略。 I need to set local GPO in device using C#.我需要使用 C# 在设备中设置本地 GPO。 computer configuration >> windows settings >> security settings >> account policies >> Password policy I need to read this and set new password policy计算机配置 >> windows 设置 >> 安全设置 >> 帐户策略 >> 密码策略 我需要阅读此内容并设置新的密码策略

First off, let me just say you are trying to tackle a very difficult task.首先,我只想说您正在尝试解决一项非常困难的任务。 The way I would try to tackle this would be to try find and modify the registry keys pertaining to those policies but that by itself is not an easy feat, you can see for yourself if you monitor the registry activity using something like ProcMon (Process Monitor).我尝试解决这个问题的方法是尝试查找和修改与这些策略相关的注册表项,但这本身并不是一件容易的事,如果您使用类似ProcMon (Process Monitor) 来监控注册表活动,您可以自己查看)。 It might end up being more work than it is worth.它最终可能会比它的价值更多。

But say you do have a scriptable solution that you can run through command line for a batch file, then the way I would go about it in C# is create a new Process and run shell commands that way or create a batch file and execute from the code.但是说你确实有一个可脚本化的解决方案,你可以通过命令行运行批处理文件,那么我在 C# 中关于它的 go 的方式是创建一个新Process并运行 Z2591C98B70119FE624898B1E 或创建批处理文件并从 918B1E4245 命令执行代码。 Check this post for more info: Run Command Prompt Commands查看这篇文章以获取更多信息: 运行命令提示符命令

Or another way is to directly modify the registry keys in your code using the Registry and RegistryKey class from the Microsoft.Win32 namespace.或者另一种方法是使用Microsoft.Win32命名空间中的RegistryRegistryKey class 直接修改代码中的注册表项。 Check out this example: https://www.c-sharpcorner.com/UploadFile/f9f215/windows-registry/看看这个例子: https://www.c-sharpcorner.com/UploadFile/f9f215/windows-registry/

Unless there is an specific reason, if your doing this so that you don't have to change it manually every time then I would recommend just creating security template, an INF file and then importing it.除非有特定原因,如果您这样做是为了不必每次都手动更改它,那么我建议您只创建安全模板、一个INF文件然后导入它。 Just do Win + R and type in secpol.msc and right click on Security Settings and there will be an import/export option.只需执行Win + R并输入secpol.msc并右键单击Security Settings ,就会有一个导入/导出选项。 In the end, it might work to your advantage to use a security template in terms of saving time or just doing it manually through secpol.msc .最后,在节省时间或仅通过secpol.msc手动执行方面,使用安全模板可能对您有利。 Good luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM