473,803 Members | 3,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enable/Disable local active directory account from code?

This MSDN article
http://msdn2.microsoft.com/en-us/lib...13(vs.80).aspx

and this codeproject article
http://www.codeproject.com/useritems/everythingInAD.asp

both show the same c# code for enabling and disabling active directory
accounts.

I'm trying to do that to a local user account and it's not working
the "userAccountCon trol" Property is null on my user.

this code fales because that property doesn't exist on my local user

DirectoryEntry user = new DirectoryEntry( member);
val = (int)user.Prope rties["userAccountCon trol"].Value;

the user I'm trying to do this to is not a domain user, the account is
local to the machine.

any ideas?
thanks
mike

PS I looped through the properties of my user and saw these;
"UserFlags"
"MaxStorage "
"PasswordAg e"
"PasswordExpire d"
"LoginHours "
"FullName"
"Descriptio n"
"BadPasswordAtt empts"
"LastLogin"
"HomeDirect ory"
"LoginScrip t"
"Profile"
"HomeDirDri ve"
"Parameters "
"PrimaryGroupID "
"Name"
"MinPasswordLen gth"
"MaxPasswordAge "
"MinPasswordAge "
"PasswordHistor yLength"
"AutoUnlockInte rval"
"LockoutObserva tionInterval"
"MaxBadPassword sAllowed"
"RasPermissions "
"objectSid"
Jun 15 '07 #1
3 15717
Try this:

// Set the 2nd bit
user.Properties["UserFlags"].Value =
((int)user.Prop erties["UserFlags"].Value) | 2;
"Michael Howes" wrote:
This MSDN article
http://msdn2.microsoft.com/en-us/lib...13(vs.80).aspx

and this codeproject article
http://www.codeproject.com/useritems/everythingInAD.asp

both show the same c# code for enabling and disabling active directory
accounts.

I'm trying to do that to a local user account and it's not working
the "userAccountCon trol" Property is null on my user.

this code fales because that property doesn't exist on my local user

DirectoryEntry user = new DirectoryEntry( member);
val = (int)user.Prope rties["userAccountCon trol"].Value;

the user I'm trying to do this to is not a domain user, the account is
local to the machine.

any ideas?
thanks
mike

PS I looped through the properties of my user and saw these;
"UserFlags"
"MaxStorage "
"PasswordAg e"
"PasswordExpire d"
"LoginHours "
"FullName"
"Descriptio n"
"BadPasswordAtt empts"
"LastLogin"
"HomeDirect ory"
"LoginScrip t"
"Profile"
"HomeDirDri ve"
"Parameters "
"PrimaryGroupID "
"Name"
"MinPasswordLen gth"
"MaxPasswordAge "
"MinPasswordAge "
"PasswordHistor yLength"
"AutoUnlockInte rval"
"LockoutObserva tionInterval"
"MaxBadPassword sAllowed"
"RasPermissions "
"objectSid"
Jun 15 '07 #2
"Michael Howes" <mh****@xforteb io.comwrote in message
news:eU******** ******@TK2MSFTN GP03.phx.gbl...
This MSDN article
http://msdn2.microsoft.com/en-us/lib...13(vs.80).aspx

and this codeproject article
http://www.codeproject.com/useritems/everythingInAD.asp

both show the same c# code for enabling and disabling active directory
accounts.

I'm trying to do that to a local user account and it's not working
the "userAccountCon trol" Property is null on my user.

this code fales because that property doesn't exist on my local user

DirectoryEntry user = new DirectoryEntry( member);
val = (int)user.Prope rties["userAccountCon trol"].Value;

the user I'm trying to do this to is not a domain user, the account is
local to the machine.

any ideas?
thanks
mike

PS I looped through the properties of my user and saw these;
"UserFlags"
"MaxStorage "
"PasswordAg e"
"PasswordExpire d"
"LoginHours "
"FullName"
"Descriptio n"
"BadPasswordAtt empts"
"LastLogin"
"HomeDirect ory" "LoginScrip t"
"Profile"
"HomeDirDri ve"
"Parameters "
"PrimaryGroupID "
"Name"
"MinPasswordLen gth"
"MaxPasswordAge "
"MinPasswordAge "
"PasswordHistor yLength"
"AutoUnlockInte rval"
"LockoutObserva tionInterval"
"MaxBadPassword sAllowed"
"RasPermissions "
"objectSid"


"UserFlags" is what you need to look at.

...
const int UF_ACCOUNTDISAB LE = 0x0002;
string userName = "someoneIdontLi ke";
using(Directory Entry comp = new DirectoryEntry( "WinNT://" +
Environment.Mac hineName + ",computer" ))
{
using(Directory Entry NewUser = comp.Children.F ind(userName, "user"))
{
NewUser.Propert ies["UserFlags"].Value =
((int)NewUser.P roperties["userFlags"].Value) ^ UF_ACCOUNTDISAB LE;
NewUser.CommitC hanges();
}
}

Note that here I'm only resetting the UF_ACCOUNTDISAB LE bit, while I'm
preserving the other bits!
Search MSDN for the other possible bits in this property.

Willy.

Jun 15 '07 #3
For a start there is no such thing as a local AD account. It is a SAM
account, so the ADSI scripting wont work. You need this code:

strComputer = "atl-ws-01"
Set objUser = GetObject("WinN T://" & strComputer & "/Guest")

objUser.Account Disabled = True
objUser.SetInfo

From here:
http://www.microsoft.com/technet/scr....mspx?mfr=true

"Michael Howes" <mh****@xforteb io.comwrote in message
news:eU******** ******@TK2MSFTN GP03.phx.gbl...
This MSDN article
http://msdn2.microsoft.com/en-us/lib...13(vs.80).aspx

and this codeproject article
http://www.codeproject.com/useritems/everythingInAD.asp

both show the same c# code for enabling and disabling active directory
accounts.

I'm trying to do that to a local user account and it's not working
the "userAccountCon trol" Property is null on my user.

this code fales because that property doesn't exist on my local user

DirectoryEntry user = new DirectoryEntry( member);
val = (int)user.Prope rties["userAccountCon trol"].Value;

the user I'm trying to do this to is not a domain user, the account is
local to the machine.

any ideas?
thanks
mike

PS I looped through the properties of my user and saw these;
"UserFlags"
"MaxStorage "
"PasswordAg e"
"PasswordExpire d"
"LoginHours "
"FullName"
"Descriptio n"
"BadPasswordAtt empts"
"LastLogin"
"HomeDirect ory" "LoginScrip t"
"Profile"
"HomeDirDri ve"
"Parameters "
"PrimaryGroupID "
"Name"
"MinPasswordLen gth"
"MaxPasswordAge "
"MinPasswordAge "
"PasswordHistor yLength"
"AutoUnlockInte rval"
"LockoutObserva tionInterval"
"MaxBadPassword sAllowed"
"RasPermissions "
"objectSid"
Jun 17 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1451
by: Greg Buckley | last post by:
I have come across an interesting problem. Let me first state that I am not a fluent ASP programmer. I am a network engineering trying to port an existing app. The app in question is currently running on IIS 5.0 (2Kserver) in a NT 4.0 domain. I am moving it to an IIS 6.0 server in a 2003 Active Directory domain. My app calls this variable <%= varUser %> and brings the users login name to the web page as well as using it to pull data...
1
4580
by: andy | last post by:
Hello, I have server-part of my program, and it very need to get ip of user that logged into the domain. All that program knew about user his Active Directory account.What I have to do? Thank you, and excuse me my english :)
1
1753
by: Robin | last post by:
When using the following ASP.Net code the error "The directory service cannot perform the requested operation on the RDN attribute of an object." is displayed when the commit changes is run. What modifications need to be made to the code to allow it to update the details? Dim rootDSE As New DirectoryEntry("LDAP://RootDSE") Dim namingContext As String = rootDSE.Properties("defaultNamingContext").Value.ToString() Dim searchRoot As New...
4
4663
by: pjdouillard | last post by:
Hello all, Here is the context of my problem: We have an ASP.NET 1.1 application that has its own application pool setup and that runs under the identity of a NT Domain service account (this is for security reason when accessing databases). We use the Integrated Windows authentication to authenticate users, and we have setup the Web.config file to authenticate those users against 3 NT Domain Global Groups. Everything is working fine...
0
1210
by: Martijn | last post by:
Hello, For those who are interested in creating Account in Active Directory here is some code I used. ublic Function create_user(ByVal firstname As String, ByVal lastname As String, _ ByVal Address As String, ByVal pwd As String) Try Dim MyRoot As DirectoryServices.DirectoryEntry
1
4785
by: bsmith | last post by:
I would like to determine if an Active Directory user account is locked. Active directory is running on W2k3 server. I also want to do this using the DirectoryEntry object. I have read a lot of threads and there does not seem to be a consistent answer.
0
6548
by: 4AspNet | last post by:
Hello. I need to disable and then enable Local Network Connection (Ethernet). Here is my code: IPGlobalProperties computerProperties = IPGlobalProperties.GetIPGlobalProperties(); NetworkInterface nics = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in nics) { if (adapter.NetworkInterfaceType !=
2
1834
by: catherine | last post by:
Hi, I am trying to work out how I can disable / enable **another** users Active Directory account not my own via C#. If I create a directory entry like so I need to know the other users password befoew I can do anything with the user. Obviously I will not know this information DirectoryEntry de = new DirectoryEntry(); de.Path = "LDAP://192.168.0.1/ CN=Users;DC=DEVELOPMENTDOMAIN";
0
1261
by: askalottaqs | last post by:
i gave up, i tried everything, i need a way to login to a remote server on the same network, just give it a username and password, and access the folders, i tried ldap but couldnt get the syntax right, i tried to install win32security but couldnt manage to.. heard of a way to do that in command line, would that be an alternative? thanks a lot T
0
9703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10550
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2972
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.