http://qs1969.pair.com?node_id=147660

enigmae has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,
I am writing a script to get a list of processes and
the owners of those processes running off win2k.
I get the process list through the WMI using win32:OLE
Where i run into problems is when i try to send a
reference to a string to the method GetOwner.
According to the WMI SDK, GetOwner takes two strings
by reference one which will get the domain name
and the other which will get the user name. The
method returns an int indicating the status of the call
I have tried sending arrays, scalars, references etc...
but it doesn't work. I even tryed sending references
to a local variant type using Win32::OLE::Variant.
if anyone has done this before, or knows how to send
these strings to the API, i would greatly appriciate
it. thanks in advance
use Win32::OLE('in'); use Win32::OLE::Variant qw(:DEFAULT nothing); $server = ""; $lobj = Win32::OLE->new('WbemScripting.SWbemLocator') or die "can't create locator:".Win32::OLE->LastError()."\n"; $lobj->{Security_}->{impersonationlevel}= 3 ; $sobj = $lobj->ConnectServer($server, 'root\cimv2') or die "can't create server object:".Win32::OLE->LastError()."\n"; $procschm = $sobj->Get('Win32_Process'); $username = new Win32::OLE::Variant(OLE::VT_BSTR, " " ); $domainname = new Win32::OLE::Variant(OLE::VT_BSTR, " " ); foreach $process (in $sobj->InstancesOf("Win32_Process")){ $i=0; #$user=\$username; #$domain=\$domainname; #$userref = \$user; #$domainref = \$domain; $process->GetOwner(\$username,\$domainname); print $process->{Name}." is pid #".$process->{ProcessID}." User Time " +.$process->{UserModeTime}."\n"; print "Owner \\\\$domainname\\ $username\n"; }