0

Hi guys,
I have found interesting code..
Unfortunatelly I dont know how to use it :/

public void Delete(string ouPath, string groupPath)
{
    if (DirectoryEntry.Exists("LDAP://" + groupPath))
    {
        try
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + ouPath);
            DirectoryEntry group = new DirectoryEntry("LDAP://" + groupPath);
            entry.Children.Remove(group);
            group.CommitChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message.ToString());
        }
    }
    else
    { 
        Console.WriteLine(path + " doesn't exist"); 
    }
}

I don't know whats the difference bewteen ouPath and groupPath
At first I thought that
groupPath is

LDAP://CN=GRUPA TESTOWA,OU=Security,OU=Groups,OU=Krakow,OU=PL-PMPL,OU=PMI,OU=Users & Workstations,DC=LORDAC,DC=NET

and ouPath is:

LDAP://OU=Security,OU=Groups,OU=Krakow,OU=PL-PMPL,OU=PMI,OU=Users & Workstations,DC=LORDAC,DC=NET

But it doesnt work...
I need to delete group and I really dunno how to modify that code :/
Can you help me?
Thanks in advance!

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by muralijoshi
0

Hi guys,
I have found interesting code..
Unfortunatelly I dont know how to use it :/

public void Delete(string ouPath, string groupPath)
{
    if (DirectoryEntry.Exists("LDAP://" + groupPath))
    {
        try
        {
            DirectoryEntry entry = new DirectoryEntry("LDAP://" + ouPath);
            DirectoryEntry group = new DirectoryEntry("LDAP://" + groupPath);
            entry.Children.Remove(group);
            group.CommitChanges();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message.ToString());
        }
    }
    else
    { 
        Console.WriteLine(path + " doesn't exist"); 
    }
}

I don't know whats the difference bewteen ouPath and groupPath
At first I thought that
groupPath is

LDAP://CN=GRUPA TESTOWA,OU=Security,OU=Groups,OU=Krakow,OU=PL-PMPL,OU=PMI,OU=Users & Workstations,DC=LORDAC,DC=NET

and ouPath is:

LDAP://OU=Security,OU=Groups,OU=Krakow,OU=PL-PMPL,OU=PMI,OU=Users & Workstations,DC=LORDAC,DC=NET

But it doesnt work...
I need to delete group and I really dunno how to modify that code :/
Can you help me?
Thanks in advance!

The code you listed above is from an awesome article written by my good friend and coworker, Thund3rstruck. You can read the entire thing with complete explanations on CodeProject. The article is entitled, "Howto: (Almost) Everything in Active Directory Via C#". Here is the link: http://www.codeproject.com/KB/system/everythingInAD.aspx#33

0

The code you listed above is from an awesome article written by my good friend and coworker, Thund3rstruck. You can read the entire thing with complete explanations on CodeProject. The article is entitled, "Howto: (Almost) Everything in Active Directory Via C#". Here is the link: http://www.codeproject.com/KB/system/everythingInAD.aspx#33

Yeah I took it directly from that page.. :)

0

Yeah I took it directly from that page.. :)

What is it that you don't understand, or cannot get working? What is the environment you are using (AD)?

0

I cannot get it working...
I dunno if I provide input data well...
ouPath and groupPath...
I think that ouPath is the same like groupPath - but without CN part, Right?
Unfortunately when I provide input in that manner, i receive an error (GENERAL ACCESS ERROR)...Its strange because I have all accesses...I can delete that group manually in AD or by using DS commands from command line...

0

Hmmh checked several combinations (paths with "LDAP://" and wothout "LDAP://")
Still it doesnt work :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.