Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating user in Active directory with c# - problem with property Allow access in Dial-in

Posted on 2008-06-25
8
Medium Priority
?
2,025 Views
Last Modified: 2013-12-16
Hi,

I have to code a .dll in c# that will create/manage user in our active directory.
Everything works great, except one thing. Im not able select "Allow access" in Dial-in tab.
I try this line "newUser.Properties["msNPAllowDialin"].Add(true);". No error there with compilation or execution. But i see no change in AD.

Later if I search for this user throught c# code, i see that property msNPAllowdialin = true.

Am I missing something in my code? Or this problem is related to our AD ?

Thanks in advance for your help !
public void selectDomain(string ldapPath) {
            currentDomainDE = new DirectoryEntry(ldapPath);
            currentDomainDE.AuthenticationType = AuthenticationTypes.Secure;
        }
 
        public void CreateUserAccount(string _userName, string _userPassword, string _firstName, string _lastName,
                                      string _description, string _company)
        {
            try
            {
                DirectoryEntry newUser = currentDomainDE.Children.Add("CN=" + _userName, "user");
                newUser.Properties["samAccountName"].Value = _userName;
                newUser.Properties["sn"].Add(_lastName);
                newUser.Properties["givenname"].Add(_firstName);
                newUser.Properties["displayname"].Add(_firstName + " " + _lastName);
                newUser.Properties["description"].Add(_description);
                newUser.Properties["company"].Add(_company);
                newUser.CommitChanges();
 
                int flags = (int)newUser.Properties["userAccountControl"].Value;
                newUser.Properties["userAccountControl"].Value = (flags ^ 0x10000);
                newUser.Properties["msNPAllowDialin"].Add(true);
                newUser.CommitChanges();
                
                this.changePasswordUser(newUser, _userPassword);
 
                this.enableAccount(newUser);
 
                newUser.Close();
                this.closedDomain();
            }
            catch { .......}

Open in new window

0
Comment
Question by:zeppyboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 21874210

AD related I believe.

It depends a little, tell us about your domain if you could? Specifically, what Functional Level is your domain set to?

Mine works when set using a small script with Functional Level set to Windows 2003 Native.

And take a look at these two articles:

http://support.microsoft.com/default.aspx?scid=kb;en-us;252398
http://support.microsoft.com/default.aspx?scid=kb;en-us;257341

Chris

0
 

Author Comment

by:zeppyboy
ID: 21878741
Thanks Chris,

As soon as my network administrator is back from vacancy (monday), i will ask him what Functional Level is our domain, then i will come back.
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 21879014

Good stuff. Hopefully that's all it is :)

Chris
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 

Author Comment

by:zeppyboy
ID: 21883075
I find the information.

Current domain functional level :
Windows 2000 mixed
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 520 total points
ID: 21883112

There we go :)

You must switch to Native for the change to work as you expect in your existing code.

For whatever reason the attribute cannot be updated correctly using ADSI / DirectoryServices via LDAP in Mixed Mode.

Alternatively bind using the WinNT interface as described in:

http://support.microsoft.com/default.aspx?scid=kb;en-us;252398

However, there are no issues with changing to Native Mode unless you have Windows NT 4 Backup Domain Controllers on the Domain.

Chris
0
 

Author Comment

by:zeppyboy
ID: 21883240
I will be surprise if we have a NT4 DC. So i will ask him if we can go with Native Mode.

If not, i will try the other option with the .dll and winnt provider.
Do you know where i can find the ADSI SDK on MS website? All the links I try redirect to microsoft.com/windows/

Thanks for your help !
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 21883493

Hmm that's a good question.

You don't seem to be able to get it any more. I know they stopped doing any work on it quite a few years ago, but that doesn't help if they're still got references to it.

You can grab the file from here though:

http://microsoftluder.dk/resources/ADSI%20SDK%205%20HTML/rtk.htm#ras

Obviously we can't vouch for the validity of the files held on the site, so use them with care.

Chris
0
 

Author Comment

by:zeppyboy
ID: 21947585
For your information, with the modification of our domain from Windows 2000 Mixed to Windows 2000 Native, everything works great now. Thanks for your help !
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question