Esteemed monks - For all the OLE guru's... I'm trying to change a user's password through OLE. I want to keep my code consistent in using OLE instead of resorting to Win32::AdminMisc. For the rest of my code, I bind to WMI with the following:
@host = ($server,"root/cimv2",$user,$password); $localWMI = Win32::OLE->new('WbemScripting.SWbemLocator') or die "Cann +ot access WMI on local machine: ", Win32::OLE->LastError; $WMI = $localWMI->ConnectServer(@host) or die "Cannot access WMI on re +mote machine: ", Win32::OLE->LastError;
I want to be able to do a similar bind to WINNT where I can use an alternate moniker than what I'm logged in with (as above). The only way I know to change a password using OLE is:
if ($myDomain = Win32::OLE->GetObject("WinNT://$server/$pworduser")) { $result=$myDomain->ChangePassword($oldpassword, $newpassword); print "Result: $result\n"; } else { print "Couldn't connect :-(\n"; }
But this only uses the logged in credentials as a moniker. Is there a host array I can use to supply different credentials to connect to WINNT instead of root\cimv2? Or is there another way I can change a password of a user (it doesn't seem as if the Win32_User object has any methods associated with it unforuntately...). All my attempts to connect to WINNT using scripting or wbemtest.exe have results in "Invalid namespace" failures. Any thoughts or comments are appreciated!

In reply to Win32::OLE Password Change? by jpavel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.