Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a faster way to change user passwords?

Status
Not open for further replies.

cpjust

Programmer
Sep 23, 2003
2,132
US
Hi, I'm writing a little command line program to change user passwords and I was wondering why it takes so long to run? Each password change takes about 1-2 seconds. (Not very long for normal use, but for stress testing it's pretty damn slow).
Is there another way of changing user passwords that would run faster than this?
Code:
#include <windows.h>
#include <Iads.h> // Add lib files:  ActiveDS.Lib ADSIid.Lib
#include <Adshlp.h>
#include <cstdio>
 
HRESULT ChangePassword( IADsUser*  pUser,
                           LPWSTR  oldPasswd,
                           LPWSTR  newPasswd )
{
  HRESULT hr = S_OK;

  if ( pUser == NULL )
  {
    return E_FAIL;
  }
 
  hr = pUser->ChangePassword( oldPasswd, newPasswd );
  printf( "User password has been changed from %S to %S\n", oldPasswd, newPasswd );
  return hr;
}
 
IADsUser* GetUserObject( LPWSTR  uPath )
{
  IADsUser* pUser = NULL;
  HRESULT hr = ADsGetObject( uPath, IID_IADsUser, (void**)&pUser );
 
  if ( FAILED( hr ) )
  {
    return NULL;
  }
 
  BSTR bstr;
  hr = pUser->get_FullName( &bstr );
  printf( "User: %S\n", bstr );
  SysFreeString( bstr );
  return pUser;
}
 

int main()
{
  HRESULT hr = CoInitialize( NULL );
  IADsUser* pUser = GetUserObject( L"WinNT://ComputerName/TestUser,user" );
 
  if ( pUser == NULL )
  {
    printf( "pUser is NULL!" );
    return 1;
  }
 
  pUser->AddRef();
  hr = ChangePassword( pUser, L"OldPass", L"NewPass" );
  pUser->Release();
 
  CoUninitialize();
  return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top