Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Win32::OLE Password Change?

by blm (Hermit)
on Mar 22, 2003 at 11:53 UTC ( #245122=note: print w/replies, xml ) Need Help??

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


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!!!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://245122]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-03-24 15:51 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (61 votes). Check out past polls.