UserPrincipal Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the UserPrincipal class.
Overloads
UserPrincipal(PrincipalContext) |
Initializes a new instance of the UserPrincipal class by using the specified context. |
UserPrincipal(PrincipalContext, String, String, Boolean) |
Initializes a new instance of the UserPrincipal class by using the specified context, SAM account name, password, and enabled value. |
UserPrincipal(PrincipalContext)
- Source:
- User.cs
- Source:
- User.cs
- Source:
- User.cs
Initializes a new instance of the UserPrincipal class by using the specified context.
public:
UserPrincipal(System::DirectoryServices::AccountManagement::PrincipalContext ^ context);
public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context);
new System.DirectoryServices.AccountManagement.UserPrincipal : System.DirectoryServices.AccountManagement.PrincipalContext -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Sub New (context As PrincipalContext)
Parameters
- context
- PrincipalContext
The PrincipalContext that specifies the server or domain against which operations are performed.
Examples
The following code example connects to the LDAP domain "fabrikam.com" with the username and password initialized in the PrincipalContext constructor to "administrator" and "securelyStoredPassword."
The properties set in the example, such as user name and email address, are created under the container specified in the PrincipalContext constructor: "CN=Users,DC=fabrikam,DC=com."
PrincipalContext ctx = new PrincipalContext(
ContextType.Domain,
"fabrikam.com",
"CN=Users,DC=fabrikam,DC=com",
"administrator",
"securelyStoredPassword");
UserPrincipal usr = new UserPrincipal(ctx);
usr.Name = "Jim Daly";
usr.Description = "This is the user account for Jim Daly";
usr.EmailAddress = "jimdaly@fabrikam.com";
usr.SetPassword("securelyStoredPassword");
usr.Save();
usr.Dispose();
ctx.Dispose();
Remarks
The user principal account is not persisted when it is created. To save the account, call the Save method.
Applies to
UserPrincipal(PrincipalContext, String, String, Boolean)
- Source:
- User.cs
- Source:
- User.cs
- Source:
- User.cs
Initializes a new instance of the UserPrincipal class by using the specified context, SAM account name, password, and enabled value.
public:
UserPrincipal(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::String ^ samAccountName, System::String ^ password, bool enabled);
public UserPrincipal (System.DirectoryServices.AccountManagement.PrincipalContext context, string samAccountName, string password, bool enabled);
new System.DirectoryServices.AccountManagement.UserPrincipal : System.DirectoryServices.AccountManagement.PrincipalContext * string * string * bool -> System.DirectoryServices.AccountManagement.UserPrincipal
Public Sub New (context As PrincipalContext, samAccountName As String, password As String, enabled As Boolean)
Parameters
- context
- PrincipalContext
The PrincipalContext that specifies the server or domain against which operations are performed.
- samAccountName
- String
The SAM account name for this user principal.
- password
- String
The password for this account.
- enabled
- Boolean
A Boolean value that specifies whether the account is enabled.
Remarks
The user principal account is not persisted when it is created. To save the account, call the Save method.
Applies to
.NET