http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netuserchangepassword.asp

Platform SDK: Network Management
NetUserChangePassword

The NetUserChangePassword function changes a user's password for a specified network server or domain.

NET_API_STATUS NetUserChangePassword(
  LPCWSTR domainname,
  LPCWSTR username,
  LPCWSTR oldpassword,
  LPCWSTR newpassword
);

Parameters

domainname
    [in] Pointer to a constant string that specifies the DNS or NetBIOS name of a remote server or domain on which the function is to execute. If this parameter is NULL, the logon domain of the caller is used.

        Windows NT:  This string must begin with \\.

username
    [in] Pointer to a constant string that specifies a user name. The NetUserChangePassword function changes the password for the specified user.

    If this parameter is NULL, the logon name of the caller is used. For more information, see the following Remarks section.
oldpassword
    [in] Pointer to a constant string that specifies the user's old password.
newpassword
    [in] Pointer to a constant string that specifies the user's new password.

Return Values

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes.
Return code     Description
ERROR_ACCESS_DENIED     The user does not have access to the requested information.
ERROR_INVALID_PASSWORD     The user has entered an invalid password.
NERR_InvalidComputer     The computer name is invalid.
NERR_NotPrimary     The operation is allowed only on the primary domain controller of the domain.
NERR_UserNotFound     The user name could not be found.
NERR_PasswordTooShort     The password is shorter than required. (The password could also be too long, be too recent in its change history, not have enough unique characters, or not meet another password policy requirement.)
Remarks

If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management user functions. For more information, see IADsUser and IADsComputer.

If you call this function on a domain controller that is running Active Directory, access is allowed or denied based on the access control list (ACL) for the securable object. The default ACL permits only Domain Admins and Account Operators to call this function. On a member server or workstation, only Administrators and Power Users can call this function. A user can change his or her own password. For more information, see Security Requirements for the Network Management Functions. For more information on ACLs, ACEs, and access tokens, see Access Control Model.

    Windows NT:  A server or domain can be configured to require a user to log on before changing the password on a user account. In that case, only members of the Administrators or Account Operators local group or the user can change the password for a user account. If logon is not required, a user can change the password for any user account, as long as the user knows the current password.

The security descriptor of the User object is used to perform the access check for this function. In addition, the caller must have the "Change password" control access right on the User object. This right is granted to Anonymous Logon and Everyone by default.

Note that for the function to succeed, the oldpassword parameter must match the password as it currently exists.

In some cases, the process that calls the NetUserChangePassword function must also have the SE_CHANGE_NOTIFY_NAME privilege enabled; otherwise, NetUserChangePassword fails and GetLastError returns ERROR_ACCESS_DENIED. This privilege is not required for the LocalSystem account or for accounts that are members of the administrators group. By default, SE_CHANGE_NOTIFY_NAME is enabled for all users, but some administrators may disable the privilege for everyone. For more information about account privileges, see Privileges and Authorization Constants.

See Forcing a User to Change the Logon Password for a code sample that demonstrates how to force a user to change the logon password on the next logon using the NetUserGetInfo and NetUserSetInfo functions.

User account names are limited to 20 characters and group names are limited to 256 characters. In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters: ", /, \, [, ], :, |, <, >, +, =, ;, ?, *. Names also cannot include characters in the range 1-31, which are nonprintable.

    Windows NT 4.0:  Calls to this function fail if an account name does not meet the criteria outlined previously.

    Windows Me/98/95:  You can use the PwdChangePassword function to change a user's Windows logon password on these platforms. The PwdChangePassword function is defined in the header file Pwdspi.h, which is distributed with the Windows 95 Driver Development Kit (DDK). For more information about PwdChangePassword, see the Windows 95 DDK documentation. For more information about designing a routine to change domain passwords on these platforms, as well as a code sample, see the following article in the Microsoft Knowledge Base:

    ARTICLE ID: Q177200
    TITLE: HOWTO: Programmatically Change Network Password Under Windows 95.

Example Code

The following code sample demonstrates how to change a user's password with a call to the NetUserChangePassword function. All parameters to the function are required.

#ifndef UNICODE
#define UNICODE
#endif

#include <stdio.h>
#include <windows.h>
#include <lm.h>

int wmain(int argc, wchar_t *argv[])
{
   DWORD dwError = 0;
   NET_API_STATUS nStatus;
   //
   // All parameters are required.
   //
   if (argc != 5)
   {
      fwprintf(stderr, L"Usage: %s \\\\ServerName UserName OldPassword NewPassword\n", argv[0]);
      exit(1);
   }
   //
   // Call the NetUserChangePassword function.
   //
   nStatus = NetUserChangePassword(argv[1], argv[2], argv[3], argv[4]);
   //
   // If the call succeeds, inform the user.
   //
   if (nStatus == NERR_Success)
      fwprintf(stderr, L"User password has been changed successfully\n");
   //
   // Otherwise, print the system error.
   //
   else
      fprintf(stderr, "A system error has occurred: %d\n", nStatus);

   return 0;
}

Requirements
Client     Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, or Windows NT Workstation.
Server     Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server.
Header     

Declared in Lmaccess.h; include Lm.h.
Library     

Link to Netapi32.lib.
DLL Requires Netapi32.dll.