http://qs321.pair.com?node_id=245122


in reply to Win32::OLE Password Change?

You seem a little confused but then I may be misunderstanding. The first example fragment uses WMI and the second uses ADSI through the NT namespace WinNT:://. root\cimv2 is not a user it is a namespace or context(?) for WMI. You don't need to connect with WMI to use ADSI. Also in the code:

$myDomain = Win32::OLE->GetObject("WinNT://$server/$pworduser")

The code returns a user object not a domain object. $pworduser is not the username of the account that you are using to establish privilege to alter user accounts. It should probably be something like:

$objUser = Win32::OLE->GetObject("WinNT://$server/$pworduser")

Look at Problems with Win32::OLE and ADSI in which rob_au gives code that uses an alternative username and password to connect to ADSI. Once connected you can change people's passwords with

$objUser->SetPassword($password);

When you say you are having troubles connecting to WinNT with "Invalid namespace" errors is that in the second code fragment? What NT version are you using? If you are using NT4 you may need to install Active Directory Service Interfaces for Microsoft Windows NT Server 4.0

Unfortunately I am making assumptions and I can't test this at home as I haven't the right platforms.

Replies are listed 'Best First'.
Re: Re: Win32::OLE Password Change?
by jpavel (Sexton) on Mar 24, 2003 at 18:30 UTC
    That was a huge help! I think I misspoke.... I knew I was attempting to bind to ADSI and not WMI in the second snippet. My problem was in using alternate credentials for an OLE ADSI binding.

    In case anyone reads this in the future and would like my resolution, here it is:

    $winntobj = Win32::OLE->GetObject('WinNT:') or croak( 'Cannot create WINNT object - ', $! ); if ($debug) { print "Attempting bind to WINNT on $server for authenticating $use +r/$password...\n"; } $userobj = $winntobj->OpenDSObject( "WinNT://$server/$pworduser,User", $user, $password, 1 ); my $err = Win32::OLE->LastError(); if ($err == 0) { print STDOUT "Successful authentication!\n"; else { print STDOUT $err; } $userobj->SetPassword($newpassword);
    ...and this works as long as the authenticated user has administrative rights. I'd still be interested in knowing if anyone has a WMI solution for this as well, but I am very happy using ADSI. Thanks again!!!