NetAddServiceAccount function (lmaccess.h)

The NetAddServiceAccount function creates a standalone managed service account (sMSA) or retrieves the credentials for a group managed service account (gMSA) and stores the account information on the local computer.

This function has no associated import library. You must use the LoadLibrary and GetProcAddress functions to dynamically link to Logoncli.dll.

Windows Server 2008 R2:  Installing a managed service account by using the PowerShell command line interface cmdlet to call this function fails with error code 0xC0000225 when the value of the AccountName parameter does not match the corresponding Security Accounts Manager (SAM) name of the account.

Syntax

NTSTATUS NetAddServiceAccount(
  [in, optional] LPWSTR ServerName,
  [in]           LPWSTR AccountName,
  [in]           LPWSTR Password,
  [in]           DWORD  Flags
);

Parameters

[in, optional] ServerName

The value of this parameter must be NULL.

[in] AccountName

The name of the account to be created.

[in] Password

This parameter is reserved. Do not use it.

[in] Flags

This parameter can be the following value.

Value Meaning
SERVICE_ACCOUNT_FLAG_LINK_TO_HOST_ONLY
0x00000001
No standalone managed service account is created. If a service account with the specified name exists, it is linked to the local computer. This flag is ignored if the account name is an existing gMSA.

Return value

If the function succeeds, it returns STATUS_SUCCESS.

If the function fails, it returns an error code.

Requirements

Requirement Value
Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header lmaccess.h
DLL Netapi32.dll

See also

NetEnumerateServiceAccounts

NetIsServiceAccount

NetRemoveServiceAccount