I have written a program in vbscript for getting system usage information, but while tried the same in perl failed to get the data.
' run as cscript hello.vbs Dim strMessage strMessage = "Hello world in VB Script!" WScript.Echo strMessage strComputer = "." Set objWMIService = GetObject("winmgmts:" & _ "{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colSettings Wscript.Echo "Total Physical Memory: " & objOperatingSystem.TotalVi +sibleMemorySize Wscript.Echo "Free Physical Memory: " & objOperatingSystem.FreePhys +icalMemory Wscript.Echo "Total Virtual Memory Size: " & objOperatingSystem.Tot +alVirtualMemorySize Wscript.Echo "Free Virtual Memory Size: " & objOperatingSystem.Fre +eVirtualMemory Next 'also want to get percentage of CPU, Memory, VirtualMemory used
Here adding my perl script.
use strict; use Win32::OLE qw( in ); my $NameSpace = "root/cimv2"; my $Machine = shift @ARGV || "."; $Machine =~ s/^[\\\/]+//; print $Machine."\n"; my $WMIServices = Win32::OLE->GetObject( "winmgmts:{impersonationLevel + = impersonate}!//$Machine/$NameSpace" ) || die; # get TotalVisibleMemorySize, FreePhysicalMemory, TotalVirtualMemoryS +ize, FreeVirtualMemory print "Win32_OperatingSystem: "; my $memOS = $WMIServices->InstancesOf(Win32_OperatingSystem); printf "%s %ld %ld %ld %ld",$memOS->{Name}, $memOS->{TotalVisibleMemor +ySize}, $memOS->{FreePhysicalMemory}, $memOS->{TotalVirtualMemorySiz +e}, $memOS->{FreeVirtualMemory};
20051228 Janitored by Corion: Added formatting
In reply to How to write vbscript equivalent to perl by shanthi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |