Given its running-name, like "Virtual Disk Service", is there some sort-of simple way to find its PID? I found a code snippet on stackoverflow and I can't understand it at all:
use Win32::OLE qw(in);
sub matching_processes {
my($pattern) = @_;
my $objWMI = Win32::OLE->GetObject('winmgmts://./root/cimv2');
my $procs = $objWMI->InstancesOf('Win32_Process');
my @hits;
foreach my $p (in $procs) {
push @hits => [ $p->Name, $p->ProcessID ]
if $p->Name =~ /$pattern/;
}
I've looked at Win32::OLE and I cannot figure out what the "GetObject" does. Its description is
Win32::OLE->GetObject(MONIKER, DESTRUCTOR)
The GetObject() class method returns an OLE reference to the specified object. The object is specified by a pathname optionally followed by additional item subcomponent separated by exclamation marks '!'. The optional DESTRUCTOR argument has the same semantics as the DESTRUCTOR in new() or GetActiveObject()
Which I mostly can't understand. And worse, the man page for ::OLE doesn't seem to have a InstancesOf method {nor did I see anything in the man page about an "in" that could be exported}. I'm completely baffled. There must be a less obscure want to do this.
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.