http://qs1969.pair.com?node_id=519555


in reply to How to write vbscript equivalent to perl

here we are:
use strict; use Win32::OLE qw( in ); use constant wbemFlagReturnImmediately => 0x10; use constant wbemFlagForwardOnly => 0x20; my $NameSpace = "root\\cimv2"; my $Machine = shift @ARGV || "."; $Machine =~ s/^[\\\/]+//; print $Machine. "\n"; my $WMIServices = Win32::OLE->GetObject( "winmgmts:{impersonationLevel = impersonate}!\\\\$Machine\\$NameSp +ace") || die; # get TotalVisibleMemorySize, FreePhysicalMemory, TotalVirtualMemoryS +ize, FreeVirtualMemory print "Win32_OperatingSystem: "; my $col = $WMIServices->ExecQuery( "SELECT * FROM Win32_OperatingSyste +m", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly ); foreach my $memOS (in $col) { printf "%s %ld %ld %ld %ld", $memOS->{Name}, $memOS->{TotalVisibleMemorySize}, $memOS->{FreePhysicalMemory}, $memOS->{TotalVirtualMemorySize}, $memOS->{FreeVirtualMemory}; }