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

Discussion in 'Perl Misc' started by Przemyslaw, Apr 29, 2013.

  1. Przemyslaw

    Przemyslaw Guest

    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
    Przemyslaw, Apr 29, 2013
    #1
    1. Advertising

  2. Przemyslaw

    Przemyslaw Guest

    Re: [Win32::OLE] - how to get message like "Invalid Class" fromwbemtest tool

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

    >
    > > 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?

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

    Przemyslaw
    Przemyslaw, Apr 30, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    488
    Patrick.O.Ige
    Jul 16, 2006
  2. Drew Pihera
    Replies:
    0
    Views:
    637
    Drew Pihera
    Feb 4, 2004
  3. Shaun Clowes

    Win32::OLE and CDO Message Filters

    Shaun Clowes, Nov 11, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    248
    Shaun Clowes
    Nov 12, 2003
  4. Lance Hoffmeyer
    Replies:
    0
    Views:
    238
    Lance Hoffmeyer
    Nov 17, 2003
  5. pdfella
    Replies:
    1
    Views:
    167
    Brian Helterline
    Dec 14, 2006
Loading...

Share This Page