Extract used RAM of program by batch

2

1

What is the easiest way of checking the amount of RAM a specific program uses with a batch file?

I know that i can access the whole information by:

set tempfile=%temp%\temp.file
tasklist >%tempfile%

And then get a list like:

Abbildname                     PID Sitzungsname       Sitz.-Nr. Speichernutzung
========================= ======== ================ =========== ===============
System Idle Process              0 Services                   0             4 K
System                           4 Services                   0            32 K
smss.exe                       404 Services                   0           504 K
csrss.exe                      512 Services                   0         2.256 K

But how can I extract for example the amount of RAM (here "Speichernutzung") the process csrss.exe uses? Ideally with built in functions of Windows.

Heikkisorsa

Posted 2016-09-27T08:08:31.447

Reputation: 25

Very much related, not quite a dupe, although the answer does suggest the answer http://superuser.com/questions/791998/windows-batch-file-wmi-taskkill-process-based-on-memory-usage

– Dave – 2016-09-27T08:21:27.627

Answers

2

Try

wmic process where name='firefox.exe' get WorkingSetSize

Source

enter image description here

To store as a variable try (use %% if running from a bat file, or single % if running from command prompt)

for /f %a in ('wmic process where "Name='outlook.exe'" get WorkingSetSize^|findstr [0-9]') do set "var=%a"

enter image description here

Dave

Posted 2016-09-27T08:08:31.447

Reputation: 24 199

That works like a charm. Now I just have to extract this value as a variable, so I can do a check (smaller as XX). How can I achieve that? – Heikkisorsa – 2016-09-27T08:32:55.950