Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Subject: Obtaining Memory Available

Original Message
Name: dos4google
Date: April 25, 2008 at 09:50:07 Pacific
Subject: Obtaining Memory Available
OS: Win
CPU/Ram: 1gb
Model/Manufacturer: Dell
Comment:
Hi all I want to write a simple script to get the memory available on a machine using the mem command...Problem is mem returns a few lines of info, what is the best way to parse this and get the number that I want after typing the mem command?

Any help appreciated,


Report Offensive Message For Removal

Response Number 1
Name: klint
Date: April 25, 2008 at 11:09:08 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
Just a request for clarification: you've got Windows, with 1 GB memory. MEM is a legacy 16-bit command that runs under the Virtual DOS machine (NTVDM.) It only ever reports a maximum of 640 KB of conventional memory and 1 MB (not 1 GB) of extended memory. Is this really the value you want to obtain, or are you looking for the amount of free memory available to Windows?

Report Offensive Follow Up For Removal

Response Number 2
Name: IVO
Date: April 25, 2008 at 12:52:46 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
More precisely mem reports up to 16 MB of extended and expanded memory, not just 1 MB. So stated, klint is right in pointing out mem is a legacy command bound to 16 bit memory addressing segmented architecture.

Report Offensive Follow Up For Removal

Response Number 3
Name: dos4google
Date: April 25, 2008 at 15:43:47 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
Hi thanks for the response - I really need to find out how
much memory is available on the machine to run an
application..Eg a script runs that works out that the machine
has a total of 1gb RAM available and then accordingly sets a
variable for the application to know to use half of the
memory available on the machine e.g 512mb....

I hope this makes things clearer, any advice would be
appreciated


Report Offensive Follow Up For Removal

Response Number 4
Name: Razor2.3
Date: April 28, 2008 at 02:16:30 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
"available" as in free, or "available" as in total?

And "RAM" as in physical memory or "RAM" as in physical memory + page file?

EDIT: Also, how do you want this number? B? KB? MB?


Report Offensive Follow Up For Removal

Response Number 5
Name: dos4google
Date: April 28, 2008 at 06:39:09 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
Hi,

I am after the RAM that is available in total. RAM in terms of Physical Memory,

So my machine has 3GB of RAM when I look at the System properties,

I would like to see the information in MB ideally

Thanks,


Report Offensive Follow Up For Removal

Response Number 6
Name: Razor2.3
Date: April 28, 2008 at 18:40:00 Pacific
Subject: Obtaining Memory Available
Reply: (edit)
So this is the type of problem VBScript with WMI excels at.

But it's not perfect: WMI needs to be running. This isn't normally a problem, but you never know how people modify their startup services. Also, this counts the total MB of each RAM module and adds them up, so it doesn't account for onboard devices stealing system memory. For instance, this PC has two 256MB chips in it, so the script reports 512MB; System Properties reports 504MB of RAM. Apparently, 8MB is reserved for the onboard video.

With that out of the way, this is a 6 line VBScript. If you're running it through cscript, it'll print the total MB of RAM. If not, it won't. Either way, the script will set the ERRORLEVEL to whatever it found. This allows you to do something like this from a command script:

totMem.vbs
SET /A halfMem=%ERRORLEVEL% / 2
yourApp -mem %halfMem%

Why? Because I'm really just that nice and it was one extra line.

Script follows:

For Each o In GetObject("winmgmts:").InstancesOf("Win32_PhysicalMemory")
mem = mem + CDbl(o.Capacity) / 2 ^ 20
Next
On Error Resume Next
WScript.StdOut.WriteLine mem
WScript.Quit mem


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Obtaining Memory Available

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software



Version Tracker Pro
Keep your software current and secure, effortlessly

Click Here for a Free Scan

Driver Agent
Automatically find the latest drivers for your computer.
Click Here for a Free Scan



The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC