36

Is there a command line utility within Windows or third-party program that can retrieve available RAM on a machine? (Since I don't believe this can be done in pure JAVA, since it is run within a virtual machine, that has preset / allocated RAM)?

3
  • 1
    Your question title is a bit different from the question text. Would you rather retrieve it in java? Commented Feb 1, 2012 at 12:43
  • @diggingforfire If possible, the suggestions so far are not very good
    – Mike
    Commented Feb 1, 2012 at 13:21
  • Your actual question "How to retrieve available RAM from Windows command line" has already been answered. You should be more clear, if your question was intended to be "How to retrieve available RAM from Windows in java", then the title is misleading. But even the answer to that has already been given. You can simply parse the output from the systeminfo command. Commented Feb 1, 2012 at 14:21

13 Answers 13

46

systeminfo is a command that will output system information, including available memory

2
  • upvoted it's native; but it's localized and rounds and adds commas. Total Physical Memory: 3,794 MB
    – n611x007
    Commented Jul 12, 2015 at 12:44
  • Powershell way with proper unit format: Get-CIMInstance Win32_OperatingSystem | Select -Property @{L='FreePhysicalMemory (MB)';E={$_.FreePhysicalMemory/1KB}} Commented May 16 at 11:40
34
wmic OS get FreePhysicalMemory /Value
1
  • Would anyone know what units the value it gives back is? I thought it was Bytes but my math doesn't otherwise workout to the true value I have
    – Kayracer
    Commented May 1, 2021 at 17:31
23

Use wmic computersystem get TotalPhysicalMemory. E.g.:

C:\>wmic computersystem get TotalPhysicalMemory
TotalPhysicalMemory
4294500352
2
  • Sorry, I meant available memory, rather then total memory
    – Mike
    Commented Feb 1, 2012 at 12:50
  • upvoted for Single Numeral Output With Header - TotalPhysicalMemory\n1234567890
    – n611x007
    Commented Jul 12, 2015 at 12:43
10
wmic OS get TotalVisibleMemorySize /Value

Note not TotalPhysicalMemory as suggested elsewhere

2
  • This won't give the available RAM but the total RAM. For the available RAM, the answer by @Everardo is the correct one - wmic OS get FreePhysicalMemory /Value
    – laurent
    Commented Mar 31, 2014 at 16:03
  • @OrangeDog What OS? Just tried this on Win7 x64 and Windows 10 x64 - it's still valid.
    – noonand
    Commented Jun 17, 2016 at 13:36
9

There is a whole bunch of useful low level tools from SysSnternals.

And psinfo may be the most useful.

I used the following psinfo switches:

-h        Show installed hotfixes.
-d        Show disk volume information.

Sample output is this:

c:> psinfo \\development -h -d

PsInfo v1.6 - local and remote system information viewer
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com


System information for \\DEVELOPMENT:
Uptime: 28 days, 0 hours, 15 minutes, 12 seconds
Kernel version: Microsoft Windows XP, Multiprocessor Free
Product type Professional
Product version: 5.1
Service pack: 0
Kernel build number: 2600
Registered organization: Sysinternals
Registered owner: Mark Russinovich
Install date: 1/2/2002, 5:29:21 PM
Activation status: Activated
IE version: 6.0000
System root: C:\WINDOWS
Processors: 2
Processor speed: 1.0 GHz
Processor type: Intel Pentium III
Physical memory: 1024 MB
Volume Type Format Label Size Free Free
A: Removable 0%
C: Fixed NTFS WINXP 7.8 GB 1.3 GB 16%
D: Fixed NTFS DEV 10.7 GB 809.7 MB 7%
E: Fixed NTFS SRC 4.5 GB 1.8 GB 41%
F: Fixed NTFS MSDN 2.4 GB 587.5 MB 24%
G: Fixed NTFS GAMES 8.0 GB 1.0 GB 13%
H: CD-ROM CDFS JEDIOUTCAST 633.6 MB 0%
I: CD-ROM 0% Q: Remote 0%
T: Fixed NTFS Test 502.0 MB 496.7 MB 99%
OS Hot Fix Installed
Q147222 1/2/2002
Q309521 1/4/2002
Q311889 1/4/2002
Q313484 1/4/2002
Q314147 3/6/2002
Q314862 3/13/2002
Q315000 1/8/2002
Q315403 3/13/2002
Q317277 3/20/2002
1
  • The psinfo tool does not show any ram usage, it only shows the total Physical memory. Ah and calling it the first time on a command line without UI, add .\PsInfo.exe -accepteula. Commented May 16 at 11:35
8

Bit old but I wanted to know similar. Just adding the solution I came across since IMO the best answer came from Everardo w/ Physical Memory

wmic OS get FreePhysicalMemory /Value

This lead me to look deeper into wmic... Keep in mind Free Physical Memory is not the type to look at.

wmic OS get FreePhysicalMemory,FreeVirtualMemory,FreeSpaceInPagingFiles /VALUE

This returns something like...

FreePhysicalMemory=2083440
FreeSpaceInPagingFiles=3636128
FreeVirtualMemory=842124
1
  • isn't it TotalVisibleMemorySize ?
    – Eboubaker
    Commented Nov 22, 2019 at 22:27
6
PS C:\Users\Rack> systeminfo | findstr "System Memory"
System Boot Time:          5/5/2016, 11:10:41 PM
System Manufacturer:       VMware, Inc.
System Model:              VMware Virtual Platform
System Type:               x64-based PC
System Directory:          C:\Windows\system32
System Locale:             en-us;English (United States)
Total Physical Memory:     40,959 MB
Available Physical Memory: 36,311 MB
Virtual Memory: Max Size:  45,054 MB
Virtual Memory: Available: 41,390 MB
Virtual Memory: In Use:    3,664 MB
1
  • Perhaps better changing the string to just "Memory" viz. systeminfo | findstr "Memory". This will only give you back five entries, all connected with memory
    – noonand
    Commented Jun 17, 2016 at 13:30
2

Powershell version of the posted wmic commands:

Get-CIMInstance Win32_OperatingSystem | Select *memory*

FreePhysicalMemory     : 1507688
FreeVirtualMemory      : 2131128
MaxProcessMemorySize   : 137438953344
TotalVirtualMemorySize : 13639352
TotalVisibleMemorySize : 8214848
1

This cannot be done in pure java. But you can run external programs using java and get the result.

Process p=Runtime.getRuntime().exec("systeminfo");
Scanner scan=new Scanner(p.getInputStream());
while(scan.hasNext()){
    String temp=scan.nextLine();
    if(temp.equals("Available Physical Memmory")){
       System.out.println("RAM :"temp.split(":")[1]);
       break;
    }
}
1

Try MemLog. It does the job perfectly and quickly.

Download via one of many mirrors, e.g. this one: SoftPedia page for MemLog.
(MemLog's author has a web site. But this is down some times. Wayback machine snapshot here.)

Example output:

C:\>memlog
2012/02/01,13:22:02,878956544,-1128333312,2136678400,2138578944,-17809408,2147352576

878956544 being the free memory

1

Here is a pure Java solution actually:

public static long getFreePhysicalMemory()
{
    com.sun.management.OperatingSystemMXBean bean =
            (com.sun.management.OperatingSystemMXBean)
                    java.lang.management.ManagementFactory.getOperatingSystemMXBean();
    return bean.getFreePhysicalMemorySize();
}
3
  • Please note: this is platform-specific and may not be available on all hardware / software platforms.
    – Nick
    Commented Jan 17, 2017 at 1:51
  • @Nick: But it generally works on Windows so it's already a good start Commented Jan 17, 2017 at 7:11
  • yes, you are correct, sorry, i should have pointed that out since the question was windows specific.
    – Nick
    Commented Jan 17, 2017 at 15:07
0

Just in case you need this functionality in a Java program, you might want to look at the sigar API: http://www.hyperic.com/products/sigar

Actually, this is no answer to the question, I know, but a hint so you don't have to reinvent the wheel.

0

As the question was about the available RAM form a window commande line, here is the answer :

c:\>wmic OS get FreePhysicalMemory 

you can get all the information you need about memory and other things using the global commande

c:\>wmic OS

After that you'll only have the add a filter using get yourFilterName

Hope this will help ;)

Not the answer you're looking for? Browse other questions tagged or ask your own question.