Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Disable/enable user, ADSI

Posted on 2004-03-25
8
Medium Priority
?
549 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

719 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