Article ID: 306271 - Last Review: December 6, 2006 - Revision: 5.1 How to add a user to the local system by using Directory Services in Visual Basic .NET or in Visual Basic 2005
This article was previously published under Q306271 On This PageSUMMARY
This article describes how to use the DirectoryServices namespace to add a user to the local system and a group. Requirements
Create the Sample
Code ExplanationCreate a New Directory EntryWhen you create the directory entry in this sample, it is assumed that the system is running Microsoft Windows NT, Windows 2000, or Windows XP. Note that the string that is passed to the DirectoryEntry constructor begins with "WinNT://". You can also run Directory Services on other third-party operating systems.Add the Directory Entry to the Directory TreeThe following code adds a DirectoryEntry of type user with the value of TestUser1 to the Active Directory tree.Set the Password and Description for the New User AccountThe following code calls the Invoke method to invoke the SetPassword and Put methods of the DirectoryEntry object. This sets the password and assigns a description to the user account. This code also calls the CommitChanges method to save the changes.Add the Account to a GroupThe first step to add the account to a group is to define a variable of type DirectoryEntry. Then you call the Find method of the Children member of the ActiveDirectory class to populate the variable. In this case, the Guest group is the target of the search. This code tests the value that the Find method returns to determine if the group has been found. If the group is found, the new user account is added to the group.TroubleshootingThe code in this article fails if you try to run the code without the sufficient privileges to create a user account. For the code to complete successfully, the currently logged on user must be a member of the Administrators group or have specific permissions that allow the user to create user accounts.REFERENCESFor more information about the Active Directory Service Interfaces, visit the following Microsoft Developer Network (MSDN) Web site: http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adinterface.asp
(http://www.microsoft.com/windows2000/techinfo/howitworks/activedirectory/adinterface.asp)
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
