<[EMAIL PROTECTED]> writes:

> I am guessing that WMI probably has the answer

Quite so.  See attached regsize.pl script.

Run it as "regsize.pl --help" for documentation.  But briefly...

Running "regsize.pl" will show the maximum size and current size of
the registry.

Running "regsize.pl --set 100" will set the maximum size to 100
megabytes.

(Also recognizes "--remote <host>" to operate on a remote machine.)

Please try it out and let me know how it goes.  If it works, I will
bundle it with the next release of Unattended.

 - Pat

# Script to query/set the registry size.

use warnings;
use strict;
use Getopt::Long;
use Pod::Usage;
use Win32::OLE;

my %opts;
GetOptions (\%opts, 'help', 'set=s', 'force', 'remote=s')
    or pod2usage (2);

(exists $opts{'help'})
    and pod2usage ('-exitstatus' => 0, '-verbose' => 2);

# Ensure no arguments after options.
scalar @ARGV == 0
    or pod2usage (2);

# Bomb out completely if COM engine encounters any trouble.
Win32::OLE->Option ('Warn' => 3);

# Get a handle to the SWbemServices object of the machine.
my $computer = Win32::OLE->GetObject (exists $opts{'remote'}
                                      ? "WinMgmts://$opts{'remote'}/"
                                      : 'WinMgmts:');

# Get SWbemObjectSet of registries (there should be only one).  See
# <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_registry.asp>.
my $regs_set = $computer->InstancesOf ('Win32_Registry');

# Convert set to a Perl array.
my @regs = Win32::OLE::Enum->All ($regs_set);

# Loop through, querying and optionally setting size.
foreach my $reg (@regs) {
    my $max = $reg->{'MaximumSize'};
    my $cur = $reg->{'CurrentSize'};
    print "Maximum reg size: $max ($cur used)\n";

    if (exists $opts{'set'}) {
        my $req = $opts{'set'};

        # Calculate new desired max size.  If requested size starts
        # with + or -, then it is relative to current max size;
        # otherwise, it is absolute.
        my $new_max = ($req =~ /^[+-]/
                       ? $max + $req
                       : $req);

        if (exists $opts{'force'} || $new_max > $max) {
            print "Setting max size to $new_max...\n";
            $reg->{'ProposedSize'} = $new_max;
            $reg->Put_ ();
            print "...done.  Will take effect at next boot.\n";
        }
        else {
            print "Requested size smaller than current size; doing nothing.\n";
        }
    }
}

exit 0;

__END__

=head1 NAME

regsize.pl - Read/set Windows registry size

=head1 SYNOPSIS

regsize.pl [ options ]

Options (may be abbreviated):

 --help                 Display help and exit
 --set <size>           Set max size to <size>
 --force                Set new size even if less than present max
 --remote <host>        Operate on <host> instead of local machine

=head1 NOTES

With no arguments, this script prints the current size and the maximum
size of the registry.

With the --set option, also resets the maximum size to the argument
provided.  The change will take effect at the next reboot.  If the
<size> option starts with a '+' or '-', then it is relative to the
present maximum size; otherwise, it is absolute.

By default, --set will grow but not shrink the size of the registry.
Add the --force option to override this behavior.

=head1 SEE ALSO

C<http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_registry.asp>

Reply via email to