Search code examples
c#windows-server-2008local-security-policy

Edit secpol.msc programmatically?


Is there a way to edit the settings from secpol.msc programmatically?

I am looking for something similar to this:

        ManagementScope scope = new ManagementScope("root\\rsop\\user\\" + user.User.Value.Replace('-', '_'));
        ObjectQuery query = new ObjectQuery("Select * from RSOP_PolicySetting");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

Is root\secpol\... an option?


Solution

  • I found the solution. Reading from the secedit export is perfect: https://gist.github.com/jkingry/421802