HerbM has asked for the wisdom of the Perl Monks concerning the following question:

Trying to CHANGE the Pagefile size through a Perl WMI script. I can update the registry settings with WMI StdRegProv, but would prefer to use the "WMI object" directly. Anyone see the problem or have code for updating ANY WMI object similar to this? Thanks...
use strict; use warnings; use Win32::OLE qw(in with); use Win32::OLE::Variant; my $server= '.' ; # "vsin0vw148.svr.us.jpmchase.net"; my $wmiService = Win32::OLE->GetObject("winmgmts:\\\\$server\\root\\CI +MV2"); if (!$wmiService) { print "... WMI connection failed! \n"; } my $PageFiles = $wmiService->ExecQuery("Select * from Win32_PageFileSe +tting"); for (in($PageFiles)) { # $_->{InitialSize} = 300; # $_->{MaximumSize} = 330; # $_->LetProperty('InitialSize', 300); # $_->LetProperty('MaximumSize', 330); $_->LetProperty(InitialSize => 300); $_->LetProperty(MaximumSize => 330); $_->SetInfo(); $_->Put(); last; # just change 1st one } exit 0;
Commented lines in the "for" passed the compiler but didn't make any changes (as far as I can see in the Registry or System control panel.) Anyone have any ideas or similar code which sets ANYTHING using Perl OLE WMI??? Thnaks

Replies are listed 'Best First'.
Re: Setting a WMI value using Perl Win32::OLE
by Anonymous Monk on Jul 10, 2011 at 05:22 UTC

    Anyone see the problem or have code for updating ANY WMI object similar to this? Thanks...

    What manual are you reading?

Re: Setting a WMI value using Perl Win32::OLE
by Anonymous Monk on Jul 10, 2011 at 06:05 UTC
    What does Win32::OLE->LastError report?
      First, thanks for nudging me to check the error OLE codes/messages that will be useful even if it doesn't solve my current problem. (I also discovered that enabling the Option: Warn => 2 calls Carp::carp for each error:

      Win32::OLE->Option(Warn => 2);


      Second, no error (0 return) is returned for the Assignment, the LetProperty, or (I added a) SetProperty.

      The Put, SetInfo, and Quit (which I also added) all return:

      Win32::OLE(0.1709) error 0x80020003: "Member not found" in METHOD/PROPERTYGET "" at D:\dev\ch\srp2.pl line 27


      So it seems the setting of the property is accepted, but it never gets updated at the actual data store. ADSI usually requires the "SetInfo" in VBS which is the reason I (semi-randomly) tried adding that. Put is mentioned in the Win32::OLE docs, and Quit was alluded to as if it might finish a 'transaction'.

      I have of course tried each separately.
        Turns out that Put_() has an UNDERSCORE even though the Win32::OLE docs (vaguely) give this as merely "Put()" -- use the underscore and it works.
        my ($init, $max) = (256, 301); for (in($PageFiles)) { showProperties($_); $_->{InitialSize} = $init; $_->{MaximumSize} = $max; $_->LetProperty('InitialSize', $init); $_->LetProperty('MaximumSize', $max); $_->SetProperty(InitialSize => $init); $_->SetProperty(MaximumSize => $max); $_->Put_() # with UNDERSCORE in method name and print "3 Put_: " . Win32::OLE->LastError . "\n\n"; last; # just change 1st one }
        Another thread here indicated the "Exec Query" SQL like interface is READ ONLY and offered the getting "instances
        #my $PageFiles = $wmiService->ExecQuery("Select * from Win32_PageFileS +etting"); my $PageFiles = $wmiService->InstancesOf("Win32_PageFileSetting");
        But that had nothing to do with my problem -- both methods work as long as you use the proper Put_ (with underscore) method. All 3 setting methods (hash assign, Let, and Set) seem to work fine even though not sure the differences if any.