473,396 Members | 2,010 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,396 software developers and data experts.

DirectoryServices name space

Hello all

I'm trying to write a liitle application to add users to AD, when I'm trying
to add a user and a group (example code from the SDK)..... I get the
following error:

A constraint violation occurred.

I think it may be something to do with access writes, I'm not sure... I'm
logged in as system admin on my lab network.... I'm off to try and sort this
out as I need to have a working app by Monday!

No pressure.... :-)

Thanks in advance, Wayne.
Jul 19 '05 #1
2 3296

Hello all,

I'm getting there.... I now have my user object created and I can set most
of the properties that I want to... the problem now is when I'm creating my
user object the user account is disabled by default. I have been looking at
C# examples form the MSDN site... I've never written anything in flavour of
C so it's difficult for me to read code and understand what it's doing...
this is the example code:

[C#]
DirectoryEntry usr =
new DirectoryEntry("LDAP://CN=New User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val & ~ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();The following code example shows how to disable a user
account.

[C#]
DirectoryEntry usr =
new DirectoryEntry("LDAP://CN=Old User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();Can anyone convert this into VB.NET code, please.Thanks
in advance, Wayne..Microsoft ...... why don't you produce all examples in
both languages? You seem to for most not all, I don't understand... I see
this as a sign the VB will in time loose out.

"Wayne Taylor" <wt*@kryptos.co.uk> wrote in message
news:Oy**************@TK2MSFTNGP10.phx.gbl...
Hello all

I'm trying to write a liitle application to add users to AD, when I'm trying to add a user and a group (example code from the SDK)..... I get the
following error:

A constraint violation occurred.

I think it may be something to do with access writes, I'm not sure... I'm
logged in as system admin on my lab network.... I'm off to try and sort this out as I need to have a working app by Monday!

No pressure.... :-)

Thanks in advance, Wayne.

Jul 19 '05 #2
>I'm getting there.... I now have my user object created and I can set most
of the properties that I want to... the problem now is when I'm creating my
user object the user account is disabled by default. I have been looking at
C# examples form the MSDN site...

[C#]
DirectoryEntry usr =
new DirectoryEntry("LDAP://CN=New User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val & ~ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();The following code example shows how to disable a user
account.


First off - I don't think your users would be created at all - you
have to set at least the "sAMAccountName" property - it's mandatory.
Also, make sure to *not* specify the cn= prefix (as in the user name),
and make sure the SAM Account name is unique in the domain you're
creating the user in.

To create a user, bind to the container it's supposed to be created
in, and then add an entry to the container's "CHildren" property:

DirectoryEntry deContainer = new
DirectoryEntry("LDAP://CN=users,DC=fabrikam,DC=com");

DirectoryEntry deUser = deContainer.Children.Add("cn=New User",
"user");

deUser.Properties["sAMAccountName"].Value = "New_User";

Secondly, you're on the right track to enable the user - I think you
could write something like this (since you're newly creating a user,
you don't really need to read the previously set value of the property
- just set it!):

deUser.Properties["userAccountControl"].Value = UF_NORMAL_ACCOUNT;

And then lastly, commit the changes:

deUser.CommitChanges();

Now you should have a newly created user, with an enabled account.
Does it work??

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
Jul 21 '05 #3

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

Similar topics

12
by: hykim | last post by:
Hello, everyone. according to MSDN, there is any constructor of System.DirectoryServices.SearchResultCollection Class. if I implement DirectorySearcher.FindAll() method by myself, then how can I...
1
by: Jason Gleason | last post by:
I am using the following method in a web service that utilizes the system.directoryservices namespace: public ArrayList GetAllAppPools(){ System.DirectoryServices.DirectoryEntry apppools = new...
4
by: Tamir Khason | last post by:
Question: I have to list all local users for computer with their images and rights (groups, etc). How to perform it managed. Of couse I can implement WinAPI and get it old way, but the question is...
6
by: Rich Crusco via DotNetMonster.com | last post by:
I am looking for a way to convert the following vbs script to c# Const ADS_SECURE_AUTHENTICATION = 1 strADMIN = "adminaccount" strPASSWORD = "password" strUSER = "useraccount" Set dso =...
3
by: Chad Beckner | last post by:
I am starting to translate some code from ASP to ASP.NET (VB). I was able to query ADS to get a users groups that they belong to, and also query a group and get a list of users. However, I can't...
5
by: Keith Jakobs, MCP | last post by:
Hi All.... I'm having a HECK of a time connecting to Active Directory using VB in Visual Studio.NET 2003. Can anyone PLEASE help me? All I am trying to do is list the current members of our...
7
by: turbon | last post by:
Hello, I am writing code, which will copy webServices from one IIS 6.0 webserver to another and using DirentoryServices to achieve this purpose. And I have problems with authentication - I get an...
6
by: Mark Rae | last post by:
Hi, I'm in the process of updating an ASP.NET v1.1 web app to v2. The app uses ActiveDirectory a great deal, and I'm trying to use the new System.Collections.Generic namespace where possible,...
2
by: Paul Hadfield | last post by:
All, Can anyone help with an example of how to use the System.DirectoryServices name space? I've found examples on Google in C# but I've had no success trying to use them. Basically, I...
1
by: aamirghanchi | last post by:
Hi, I recently converted an ASP .net 1.1 project to 2.0 in VS 2005. Even though System.DirectoryServices reference has been added to the project, still for some reasons the Imports...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.