Geeks With Blogs
derekf's blog On C#, repackaging applications, and deploying via group policy...

Ok, part of all this we've already talked about requires that you have the policy's GUID.  But how do you get it?

Simple enough:

        private string Query(string Criteria, string Attribute)

        {

           DirectorySearcher mySearcher = new DirectorySearcher(new DirectoryEntry("LDAP://DC=DOMAIN,DC=MYCOMPANY,DC=com",    null,    null,    AuthenticationTypes.Secure    ));

            

            mySearcher.ClientTimeout = new TimeSpan(0, 0, 10);

            mySearcher.Filter = Criteria;

            mySearcher.SearchScope = SearchScope.Subtree;

 

            try

            {

                SearchResult result = mySearcher.FindOne();

 

                //if exception was not thrown, means it connected successfuly

                if (result != null)

                {

                    if(result.Properties[Attribute][0] != null)

                    {

                        mySearcher.Dispose();

                        return result.Properties[Attribute][0].ToString();

                    }

                }

            }

            catch (Exception ex)

            {

                return ex.Message;

            }

 

            mySearcher.Dispose();

            return "Not found.";          

        }

 

with the provision that the "Criteria" and "Attribute" arguments are, respectively,

 

"(&(objectCategory=groupPolicyContainer)(name=" + GUID + "))"  and "displayName" to convert from GUID to policy name, and

"(&(objectCategory=groupPolicyContainer)(displayName=" + Policy Name + "))","name" to go from policy name to GUID.

Posted on Monday, April 23, 2007 6:04 AM | Back to top


Comments on this post: Converting a policy name to a GUID

# Links (4/23/2007)
Requesting Gravatar...
.NET Handling Events in Unit Tests with anonymous delegates How to Create a Custom WPF Control WCF Virtual
Left by Member Blogs on Apr 25, 2007 9:37 PM

Your comment:
 (will show your gravatar)


Copyright © derekf | Powered by: GeeksWithBlogs.net