Solved

Disable/enable user, ADSI

Posted on 2004-03-25
8
531 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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