Use this code:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + group);
if (dirEntry != null)
{
dirEntry.Properties["member"].Add(userPrincipal.DistinguishedName);
dirEntry.CommitChanges();
dirEntry.Close();
}
if the user have access to active directory it will work fine but if user dont have permission operation will failed