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";
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.