OLE, WMI and ExecMethod - possible?

D

Daniel Berger

Hi all,

Is there a way to use ExecMethod() on a SWbemServices object via
Win32::OLE? It seems you ought to be able to exec class methods
directly, rather than iterating all "InstancesOf" and calling method
on the objects individually. Yes, I'm aware of how to do it that way,
but I think somethink like the syntax below ought to work:

use strict;
use Win32::OLE qw(in with);

my $wmi = Win32::OLE->GetObject("winmgmts:\\");
my $rv = $wmi->ExecMethod("Win32_Service","StartService","ClipSrv")
or die "Error", Win32::OLE->LastError;

print "RV: $rv\n";

I messed around with "Invoke", but that didn't seem to work either. I
also tried playing around with the constructor for $wmi, but no luck.
Am I just doing it wrong? Or is something like the syntax above just
not possible?

Regards,

Dan

Relevant link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/swbemservices.asp
 
P

Petri

Daniel Berger said:
Is there a way to use ExecMethod() on a SWbemServices object via
Win32::OLE?
my $wmi = Win32::OLE->GetObject("winmgmts:\\");

What is the backslashing supposed to do there?
my $rv = $wmi->ExecMethod("Win32_Service","StartService","ClipSrv")
or die "Error", Win32::OLE->LastError;
Relevant link:

Why do you even ask, when you are providing a direct link to the answer?
Just click on SWbemServices.ExecMethod and everything is explained to you, with
several examples in VBScript.

Had you cared to look, you would have seen that you are providing totally wrong
parameters to ExecMethod().

Here's a simple example that does what you want to do:
---8<---
#!/usr/bin/perl
use strict;
use warnings;
use Win32::OLE;

my $service = Win32::OLE->GetObject("winmgmts:Win32_Service='SETI'");
$service->StartService();
---8<---

If you absolutely must use ExecMethod, you will have to figure out how to
provide the object path parameter in Perl.


Petri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top