How can I configure Password policy in windows using group policy in c#. I need to set local GPO in device using C#. computer configuration >> windows settings >> security settings >> account policies >> Password policy I need to read this and set new password policy
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). 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. 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. Check out this example: 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. Just do Win + R and type in secpol.msc
and right click on Security Settings
and there will be an import/export option. 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
. Good luck!