Enbaling a user account with WinNT provider (Directory Services)

  • Thread starter Thread starter Eliseo Calderon
  • Start date Start date
E

Eliseo Calderon

I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks

Eliseo
 
I am resubmitting this again:

I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks
 
Have you tried setting the AccountDisabled property? I think this should do
what you want without having to bitmask the UserFlags property.

Ian

Eliseo Calderon (Verizon) said:
I am resubmitting this again:

I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks

Eliseo Calderon said:
I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks

Eliseo
 
Actually yes. It was the only way to make it work. But using that property
means I have to use an unmanaged API.

It works, but is not how I wanted to do it.

Thanks.



Ian Harding said:
Have you tried setting the AccountDisabled property? I think this should do
what you want without having to bitmask the UserFlags property.

Ian

Eliseo Calderon (Verizon) said:
I am resubmitting this again:

I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks

Eliseo Calderon said:
I have this code:

DirectoryEntry usr = new DirectoryEntry("WinNT://./guest");
int val = (int) usr.Properties["UserFlags"].Value;
usr.Properties["UserFlags"].Value = val & ~0x0002; <=== this fails
usr.CommitChanges();

I am trying to enable a usera account with the DirectoryServices class.

When the code executes, I get this error.

Error: Unspecified error at System.DirectoryServices.Interop.IAds.PutEx(...


Any ideas what I am missing? The user account I am using to execute this
program has Adminsitrator rights for the local machine.

Thanks

Eliseo
 
I did some more searching and found an MSDN article:
http://tinyurl.com/snnl
Using the example, I wrote this piece of code that will enable an disabled
account:

DirectoryEntry usr = new DirectoryEntry("WinNT://myserver/testuser");
int flags = (int) usr.Properties["UserFlags"].Value;

if ( 0 != ( flags & 0x0002 ))
{
flags = flags ^ 0x0002;
usr.Invoke( "Put", new object[] {"UserFlags", flags});
usr.CommitChanges();
}

I hadn't realised that the Invoke method was available to call methods on
the underlying ADSI object. I was hoping that it could be used to directly
set the AccountDisabled property, but that just throws an exception, can't
have everything I suppose ;-)

Anyway, this solves your problem without using unmanaged code.

Ian
 
Back
Top