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?
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;
}