Solved

Disable/enable user, ADSI

Posted on 2004-03-25
8
542 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
[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
  • 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Suggested Courses

734 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