Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Sending strings to win32:process-GetOwner() object

by enigmae (Pilgrim)
on Feb 26, 2002 at 17:38 UTC ( #147660=perlquestion: print w/replies, xml ) Need Help??

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

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

Replies are listed 'Best First'.
(tye)Re: Sending strings to win32:process-GetOwner() object
by tye (Sage) on Feb 27, 2002 at 21:19 UTC

    The reply to your first question linked to an answer that used GetOwner($u,$d) not GetOwner(\$u,\$d).

            - tye (but my friends call me "Tye")

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2023-03-27 13:13 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (65 votes). Check out past polls.