Click here to Skip to main content
15,905,504 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,all!
I want to get Local group policy list using WMI,can you give me C# code?
Posted
Updated 19-Apr-16 21:02pm

1 solution

Hi!

Try this:


C#
private void queryMethod(string queryString)
       {
           ManagementScope scope = new ManagementScope("\\\\localhost\\root\\rsop\\Computer");
           scope.Connect();

           ObjectQuery query = new ObjectQuery(queryString);
           ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

           ManagementObjectCollection queryCollection = searcher.Get();

           foreach (ManagementObject mgo in queryCollection)
           {
               textBox1.Text += mgo.Path + "\r\n";

               foreach (PropertyData q in mgo.Properties)
               {
                   textBox1.Text += q.Name + " - " + q.Value + "\r\n";
               }

               textBox1.Text += "================================\r\n";

           }

           toolStripProgressBar1.Value = 0;
       }


And queryString could be any of these:

SELECT * FROM RSOP_GPO
SELECT * FROM RSOP_PolicySetting
SELECT * FROM RSOP_Session
SELECT * FROM RSOP_RegistryPolicySetting

See additional WMI Classes here:

RSoP WMI Classes (Windows)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900