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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.