[Win32::OLE] - how to get message like "Invalid Class" from wbemtest tool

P

Przemyslaw

hi all,

I use below code to catch errors:

my $query = "Select * from Win32_Service";
my $items = $wmi->ExecQuery($query, "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly) or print "Cannot execute WMI query \'$query\': ".Win32::OLE->LastError."\n";


but Win32_Service doesn't exist and ExecQuery doesn't return any error. Win32::OLE->LastError return 0.

When I try do it by wbemtest it give me a msg box with error "Invalid class". The class doesn't exist because I don't installed WMI Provider. I want to know if WMI Provider not installed and I could get it if ExecQuery return error but it doesn't.
Is there any way to catch error message if WMI class doesn't exist?

thanks in advance

Przemyslaw
 
P

Przemyslaw

W dniu poniedziałek, 29 kwietnia 2013 23:19:13 UTC+2 użytkownik Ben Morrow napisał:
Quoth Przemyslaw:












I know pretty-much nothing about WMI, but the docmentation says



| If an error occurs when executing this method and you do not use the

| wbemFlagReturnImmediately flag, the Err object is not set until you

| attempt to access the returned object set. However, if you use the

| wbemFlagReturnWhenComplete flag, the Err object is set when the

| ExecQuery method is called.



Ben

Ben, thanks for reminder me something like as documentation :)
You are right the problem was in wbemFlagReturnImmediately flag. It doesn'tgenerete any error.
I changed of wbemFlagReturnImmediately flag to wbemFlagReturnWhenComplete and I get an error that I wanted to.
For example:
--------------------------------------------
OLE exception from "SWbemServicesEx":

Invalid class

Win32::OLE(0.1709) error 0x80041010
in METHOD/PROPERTYGET "ExecQuery" at test.pm line 332
Cannot execute WMI query 'SELECT * FROM Win32_non_existent_class': OLE exception from "SWbemServicesEx":

Invalid class

Win32::OLE(0.1709) error 0x80041010
in METHOD/PROPERTYGET "ExecQuery"
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top