You could...

(wait for it...  wait for it...)

...use WMI.

  http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_environment.asp

Attached is a script (getenv.pl) which takes a hostname as argument
and dumps its user and system environment settings.

 - Pat

use warnings;
use strict;
use Win32::OLE;

sub die_usage () {
    die "Usage: $0 <hostname>\n";
}

scalar @ARGV == 1
    or die_usage ();

my ($hostname) = @ARGV;

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

# Get a handle to the SWbemServices object of the local machine.
my $computer = Win32::OLE->GetObject ("WinMgmts://$hostname/");

# Get the SWbemObjectSet of all environment settings.  See:
# <http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_environment.asp>
my $vars_set = $computer->InstancesOf ('Win32_Environment');

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

sub dump_vars ($@) {
    my ($system, @vars) = @_;
    
    # Loop through them, printing various items of interest.
    foreach my $var (@vars) {
        $var->{'SystemVariable'} == $system
            or next;
        print "$var->{'Name'}=$var->{'VariableValue'}\n";
    }
}

print "User variables:\n";
dump_vars (0, @vars);
print "\nSystem variables:\n";
dump_vars (1, @vars);

Reply via email to