Solved

Disable/enable user, ADSI

Posted on 2004-03-25
8
523 Views
Last Modified: 2008-03-04
I have this code to enable/disable a user in ADSI:

      const int UF_ACCOUNTDISABLE = 0x0002;
                  
      try
      {
            DirectoryEntry myDirectoryEntry;
            myDirectoryEntry = new DirectoryEntry("WinNT://" + domain +"/"+username+",User");

            myDirectoryEntry.Properties["UserFlags"].Value = ((int)myDirectoryEntry.Properties["UserFlags"].Value) ^ UF_ACCOUNTDISABLE;
                  
            myDirectoryEntry.CommitChanges();
            return "ok";
      }
      catch(Exception ex)
      {
            return ex.ToString();
      }

But I just keep getting the error:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(Int32 lnControlCode, String bstrName, Object vProp) at System.DirectoryServices.PropertyValueCollection.OnClearComplete() at System.DirectoryServices.PropertyValueCollection.set_Value(Object value) at WebCreSiterWeb.CreateWinAccount.Disable()

I have the right permissions and "domain" and username" is correct!
What is wrong?
0
Comment
Question by:aleborg
  • 2
  • 2
8 Comments
 
LVL 12

Expert Comment

by:vascov
ID: 10723362
Hi aleborg,

I think that you're trying to set a collection with the value of an int.

Do it like this:
                                                        |
                                                        v
myDirectory.Properties[ "UserFlags" ][ 0 ] = (int)(myDirectoryEntry.Properties["UserFlags"].Value ^ UF_ACCOUNTDISABLE);

hth

Vasco
0
 
LVL 12

Expert Comment

by:vascov
ID: 10737240
aleborg, did this work for you ?

Vasco
0
 

Author Comment

by:aleborg
ID: 11733755
The solution was

      const int UF_ACCOUNTDISABLE = 0x0002;
      DirectoryEntry myDirectoryEntry;
      myDirectoryEntry = new DirectoryEntry("WinNT://" + domain +"/"+username+",User");
      myDirectoryEntry.Properties["UserFlags"].Add(((int)myDirectoryEntry.Properties["UserFlags"].Value) ^ UF_ACCOUNTDISABLE);
      myDirectoryEntry.CommitChanges();
0
 

Author Comment

by:aleborg
ID: 11733761
How do I close the question?
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 11911294
PAQed - no points refunded (of 500)

modulo
Community Support Moderator
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

705 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now