Win32::OLE "Member not found"

Discussion in 'Perl Misc' started by Adam.L.MacKinnon@gmail.com, Apr 3, 2008.

  1. Guest

    Hi,

    Am attempting to run the simple script as follows (sourced from:
    http://techtasks.com/code/viewbookcode/443)

    use strict;
    use warnings;
    use Data::Dumper;
    use Win32::OLE;
    $Win32::OLE::Warn = 3;

    #use lib 'H:\dev\perl\NSLC-Store-Mgmt\lib';
    #use NSLC::Store::Mgmt;

    my %args;

    $args{name} = 'TESTVAR';
    $args{value} = 'TESTVALUE';
    $args{target} = '.';

    set_env_var(\%args);

    sub set_env_var {
    my ($args,) = @_;
    my $strVarName = $args->{name};
    my $strVarValue = $args->{value};
    my $strComputer = $args->{target};

    my $objVarClass = Win32::OLE->GetObject('winmgmts://' .
    $strComputer . '/root/cimv2:Win32_Environment');
    my $objVar = $objVarClass->SpawnInstanceobjVar->Name eq
    $strVarName;
    $objVar->{VariableValue} = $strVarValue;
    $objVar->{UserName} = '<SYSTEM>';
    $objVar->PutWScript->Echo('Created environment variable ' .
    $strVarName);
    }

    The following message is returned.
    retrying default method at C:/Perl/site/lib/Win32/OLE/Lite.pm line
    156.
    Win32::OLE(0.1403) error 0x80020003: "Member not found"
    in METHOD/PROPERTYGET "" at H:\dev\perl\test\setenv.pl line 28
    shell returned 9

    I am completely new to using perl in a windows environment and am not
    sure where to start debugging. I have read all that I can via module
    docs and web information but am still having no luck.
    As far as I can tell, syntactically the script is fine but I am not
    sure how the guts of $objVarClass->SpawnInstanceobjVar->Name eq
    $strVarName; is working. I am running this on XP pro using activeperl
    5.8.8(820).

    Any insight would be appreciated.

    Thanks
     
    , Apr 3, 2008
    #1
    1. Advertising

  2. Thomas Kratz Guest

    wrote:
    > Hi,
    >
    > Am attempting to run the simple script as follows (sourced from:
    > http://techtasks.com/code/viewbookcode/443)


    This code is buggy and I suspect nobody ever tested it.

    > use strict;
    > use warnings;
    > use Data::Dumper;
    > use Win32::OLE;
    > $Win32::OLE::Warn = 3;
    >
    > #use lib 'H:\dev\perl\NSLC-Store-Mgmt\lib';
    > #use NSLC::Store::Mgmt;
    >
    > my %args;
    >
    > $args{name} = 'TESTVAR';
    > $args{value} = 'TESTVALUE';
    > $args{target} = '.';
    >
    > set_env_var(\%args);
    >
    > sub set_env_var {
    > my ($args,) = @_;
    > my $strVarName = $args->{name};
    > my $strVarValue = $args->{value};
    > my $strComputer = $args->{target};
    >
    > my $objVarClass = Win32::OLE->GetObject('winmgmts://' .
    > $strComputer . '/root/cimv2:Win32_Environment');
    > my $objVar = $objVarClass->SpawnInstanceobjVar->Name eq
    > $strVarName;


    These have to be 2 statements:

    my $objVar = $objVarClass->SpawnInstance_ # note the underscore
    $objVar->{Name} = $strVarName;

    > $objVar->{VariableValue} = $strVarValue;
    > $objVar->{UserName} = '<SYSTEM>';
    > $objVar->PutWScript->Echo('Created environment variable ' .
    > $strVarName);


    and again:

    $objVar->Put_;
    WScript->Echo('Created environment variable ' . $strVarName);
    # at least I think so, I don't know WScript


    > }
    >
    > The following message is returned.
    > retrying default method at C:/Perl/site/lib/Win32/OLE/Lite.pm line
    > 156.
    > Win32::OLE(0.1403) error 0x80020003: "Member not found"
    > in METHOD/PROPERTYGET "" at H:\dev\perl\test\setenv.pl line 28
    > shell returned 9
    >
    > I am completely new to using perl in a windows environment and am not
    > sure where to start debugging. I have read all that I can via module
    > docs and web information but am still having no luck.
    > As far as I can tell, syntactically the script is fine but I am not
    > sure how the guts of $objVarClass->SpawnInstanceobjVar->Name eq
    > $strVarName; is working. I am running this on XP pro using activeperl
    > 5.8.8(820).


    For using the WMI interface the M$ WMI Reference is the best information

    http://msdn2.microsoft.com/en-us/library/aa394572(VS.85).aspx

    Thomas

    --
    $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
     
    Thomas Kratz, Apr 8, 2008
    #2
    1. Advertising

  3. Guest

    On Apr 8, 6:09 am, Thomas Kratz <> wrote:
    > wrote:
    > > Hi,

    >
    > > Am attempting to run the simple script as follows (sourced from:
    > >http://techtasks.com/code/viewbookcode/443)

    >
    > This code is buggy and I suspect nobody ever tested it.
    >
    >
    >
    > > use strict;
    > > use warnings;
    > > use Data::Dumper;
    > > useWin32::OLE;
    > > $Win32::OLE::Warn = 3;

    >
    > > #use lib 'H:\dev\perl\NSLC-Store-Mgmt\lib';
    > > #use NSLC::Store::Mgmt;

    >
    > > my %args;

    >
    > > $args{name} = 'TESTVAR';
    > > $args{value} = 'TESTVALUE';
    > > $args{target} = '.';

    >
    > > set_env_var(\%args);

    >
    > > sub set_env_var {
    > > my ($args,) = @_;
    > > my $strVarName = $args->{name};
    > > my $strVarValue = $args->{value};
    > > my $strComputer = $args->{target};

    >
    > > my $objVarClass =Win32::OLE->GetObject('winmgmts://' .
    > > $strComputer . '/root/cimv2:Win32_Environment');
    > > my $objVar = $objVarClass->SpawnInstanceobjVar->Name eq
    > > $strVarName;

    >
    > These have to be 2 statements:
    >
    > my $objVar = $objVarClass->SpawnInstance_ # note the underscore
    > $objVar->{Name} = $strVarName;
    >
    > > $objVar->{VariableValue} = $strVarValue;
    > > $objVar->{UserName} = '<SYSTEM>';
    > > $objVar->PutWScript->Echo('Created environment variable ' .
    > > $strVarName);

    >
    > and again:
    >
    > $objVar->Put_;
    > WScript->Echo('Created environment variable ' . $strVarName);
    > # at least I think so, I don't know WScript
    >
    >
    >
    > > }

    >
    > > The following message is returned.
    > > retrying default method at C:/Perl/site/lib/Win32/OLE/Lite.pm line
    > > 156.
    > >Win32::OLE(0.1403) error 0x80020003: "Member not found"
    > > in METHOD/PROPERTYGET "" at H:\dev\perl\test\setenv.pl line 28
    > > shell returned 9

    >
    > > I am completely new to using perl in a windows environment and am not
    > > sure where to start debugging. I have read all that I can via module
    > > docs and web information but am still having no luck.
    > > As far as I can tell, syntactically the script is fine but I am not
    > > sure how the guts of $objVarClass->SpawnInstanceobjVar->Name eq
    > > $strVarName; is working. I am running this on XP pro using activeperl
    > > 5.8.8(820).

    >
    > For using the WMI interface the M$ WMI Reference is the best information
    >
    > http://msdn2.microsoft.com/en-us/library/aa394572(VS.85).aspx
    >
    > Thomas
    >
    > --
    > $/=$,,$_=<DATA>,s,(.*),$1,see;__END__
    > s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
    > $_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
    > '%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
    > print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-


    Oh man....did I really miss that? Thanks, I have it somewhat working
    now :).
     
    , Apr 8, 2008
    #3
    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. M. David Allen

    Win32::OLE, Excel, and coloring

    M. David Allen, Jun 24, 2003, in forum: Perl
    Replies:
    1
    Views:
    5,397
    Jay Tilton
    Jun 25, 2003
  2. Vinay Gupta
    Replies:
    2
    Views:
    1,110
    Michael Schlenker
    Jul 27, 2004
  3. Patrick.O.Ige

    Ole ole

    Patrick.O.Ige, Jul 16, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    498
    Patrick.O.Ige
    Jul 16, 2006
  4. Drew Pihera
    Replies:
    0
    Views:
    647
    Drew Pihera
    Feb 4, 2004
  5. Lance Hoffmeyer
    Replies:
    0
    Views:
    245
    Lance Hoffmeyer
    Nov 17, 2003
Loading...

Share This Page