473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding AD-user in AD-group

Here's code,that i think,add user in group

....
DirectoryEntry grp=new DirectoryEntry(GroupName);
MessageBox.Show(GroupName,"group to add");
try
{
if (grp!=null)
{
grp.Invoke("Add",new object[] {User.Path.ToString()});}
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding to group");
}
}
....
GroupName is something like
LDAP://cn=Admin,ou=Administration,ou=main office,dc=beta-comp,dc.com

It generate exception:
"Exception has been thrown by the target of an invocation"
Help me please!
P.S. Very sorry for my english :)
Nov 17 '05 #1
3 22169
>Here's code,that i think,add user in group
...
DirectoryEntry grp=new DirectoryEntry(GroupName);
MessageBox.Show(GroupName,"group to add");
try
{
if (grp!=null)
{
grp.Invoke("Add",new object[] {User.Path.ToString()});}
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding to group");
}
}
...
GroupName is something like
LDAP://cn=Admin,ou=Administration,ou=main office,dc=beta-comp,dc.com


What's the user LDAP path look like??

You're trying to add a user to a group, right?

Why so complicated ?? Basically, you can do:

DirectoryEntry grp = new DirectoryEntry(GroupName);
try
{
if (grp!=null)
{
grp.Properties["member"].Add(strUserLDAPString);
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding
to group");
}
}

That should do the trick.

Check out the "System.DirectoryServices Portal" on MSDN:
http://msdn.microsoft.com/library/en...sds/portal.asp

It contains TONS of samples in both VB.NET and C# - see here
http://msdn.microsoft.com/library/en...e_examples.asp
(C#)
http://msdn.microsoft.com/library/en...e_examples.asp
(VB.NET)

and tons of background info on S.DS- well worth a visit !

Marc
Nov 17 '05 #2
Thank you very much for help,it's really works.
Marc Scheuner [MVP ADSI] <m.********@inova.SPAMBEGONE.ch> wrote in message news:<2b********************************@4ax.com>. ..
Here's code,that i think,add user in group
...
DirectoryEntry grp=new DirectoryEntry(GroupName);
MessageBox.Show(GroupName,"group to add");
try
{
if (grp!=null)
{
grp.Invoke("Add",new object[] {User.Path.ToString()});}
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding to group");
}
}
...
GroupName is something like
LDAP://cn=Admin,ou=Administration,ou=main office,dc=beta-comp,dc.com


What's the user LDAP path look like??

You're trying to add a user to a group, right?

Why so complicated ?? Basically, you can do:

DirectoryEntry grp = new DirectoryEntry(GroupName);
try
{
if (grp!=null)
{
grp.Properties["member"].Add(strUserLDAPString);
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding
to group");
}
}

That should do the trick.

Check out the "System.DirectoryServices Portal" on MSDN:
http://msdn.microsoft.com/library/en...sds/portal.asp

It contains TONS of samples in both VB.NET and C# - see here
http://msdn.microsoft.com/library/en...e_examples.asp
(C#)
http://msdn.microsoft.com/library/en...e_examples.asp
(VB.NET)

and tons of background info on S.DS- well worth a visit !

Marc

Nov 17 '05 #3
Thank you very much for help,it's really works.
Marc Scheuner [MVP ADSI] <m.********@inova.SPAMBEGONE.ch> wrote in message news:<2b********************************@4ax.com>. ..
Here's code,that i think,add user in group
...
DirectoryEntry grp=new DirectoryEntry(GroupName);
MessageBox.Show(GroupName,"group to add");
try
{
if (grp!=null)
{
grp.Invoke("Add",new object[] {User.Path.ToString()});}
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding to group");
}
}
...
GroupName is something like
LDAP://cn=Admin,ou=Administration,ou=main office,dc=beta-comp,dc.com


What's the user LDAP path look like??

You're trying to add a user to a group, right?

Why so complicated ?? Basically, you can do:

DirectoryEntry grp = new DirectoryEntry(GroupName);
try
{
if (grp!=null)
{
grp.Properties["member"].Add(strUserLDAPString);
grp.CommitChanges();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"An Exception occured during adding
to group");
}
}

That should do the trick.

Check out the "System.DirectoryServices Portal" on MSDN:
http://msdn.microsoft.com/library/en...sds/portal.asp

It contains TONS of samples in both VB.NET and C# - see here
http://msdn.microsoft.com/library/en...e_examples.asp
(C#)
http://msdn.microsoft.com/library/en...e_examples.asp
(VB.NET)

and tons of background info on S.DS- well worth a visit !

Marc

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
1
by: hzgt9b | last post by:
When adding my VB .NET solution (with two sub-projects) the folder structure in VSS gets an extra level of folders... For example, here's the structure of the solution on my C:\...
3
by: Robin Thomas | last post by:
I am fairly new to ASP.NET so I think I am missing something fundamental. Anyway, quite often I am pulling data from a database, but then I need to use that data to produce more data. A simple...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
6
by: vb | last post by:
Hi, I am new to .Net. I am using a Combo Box in my windows forms. I am adding the items by creating the instances and adding the same to the list. My questions/doubts are: 1. If I have 25 to...
6
by: Rudy | last post by:
Hi all, I know this is easy, just can't seem to get it. I have a windows form, and a text box, with a value already in it. I need to add that value to a table. It's just one value, so the entire...
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
9
by: Kadett | last post by:
Hi all, I have following problem: I'm creating a ListView (Details) control at run-time and filling it with some records (let's say 10 000). This operation seems to be quite fast, but when I call...
0
by: AndyL69 | last post by:
Hello I've got a very strange Problem. When im adding a new ACE entry to a UNC Direcotry the inherented ACL's will be lost. When I'm adding a new ACE to a directory / file in this UNC path the...
8
by: Jason | last post by:
Hello, I am trying to utilitze the AJAX Control toolkit in my asp.net project. I have added a reference to AjaxControlToolkit.dll, and in my page, added these lines of code: ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.