Guildenstern has asked for the wisdom of the Perl Monks concerning the following question:

I'm writing a script that will automate the installation process of some products we're rolling out. Part of the installation is to verify that the target computer meets the minimum configuration (disk space, OS, RAM, etc). So far I've been able to find modules for disk space and operating system. I have yet to be able to find a way to determine how much RAM is installed on a computer through Perl. I've tried capturing the output of Windows' mem command, but it returns different things on different versions (plus on my NT box it only returns how much of the 640K is left).
Is there a module available that will let me check RAM? If not, is anyone aware of a Windows method that I can call through the Win32::API interface? Is the amount of installed RAM in the registry somewhere?

Guildenstern
Negaterd character class uber alles!

Replies are listed 'Best First'.
(jcwren) RE: Available RAM in Win32?
by jcwren (Prior) on Aug 30, 2000 at 18:36 UTC
    I browsed through the registry, and there doesn't *seem* to be an entry that indicates how much physical memory is installed in the machine.

    However, you could use the GlobalMemoryStatus and GlobalMemoryStatusEx functions that will return the free and used values of the amount of physically installed memory, the paging file size, the virtual memory size, and a general 'best guess' utilization expressed as a percentage. This information is in the MSDN, and can be searched for at msdn.microsoft.com, or, if you have trouble with that, I can cut-n-paste the pages to e-mail for you.

    GlobalMemoryStatus will work on any Windows 3.1 and up machine, while GlobalMemoryStatusEx requires Windows-95 and up.

    This might be a good module to write and submit to CPAN as part of the Win32 services...

    --Chris

    e-mail jcwren
      GlobalMemoryStatus is the one I was looking for. According to the online documentation, GlobalMemoryStatusEx is only supported on Windows 2000.
      I have written a small module available over at Win32::MemoryInfo. It almost cries out to have something else added to it before I submit it, though. I noticed a function called GetSystemInfo which will return processor information that might be a nice inclusion.

      Guildenstern
      Negaterd character class uber alles!
Re: Available RAM in Win32?
by Shendal (Hermit) on Aug 30, 2000 at 18:28 UTC
    Have you looked at parsing the output of winmsd? It should be available on all your Win32 platforms, and may give you more consistent results. In addition, you wouldn't have to worry about installing modules on every machine.

    Another point, winmsd can (at least on Win2k) check a different machine -- so it's conceivable that you could write your script to go out and check all these other machines from one central location. A big plus in my book.

    Cheers,
    Shendal
Re: Available RAM in Win32?
by lhoward (Vicar) on Aug 30, 2000 at 19:03 UTC
    Another option would to be to use SNMP. All NT Perfmon variables are availble through SNMP (if you configure it right). Then you can use the Net::SNMP module in your perl code to query it.