Thanks alot!

Moderator: DosItHelp
Code: Select all
@echo off
for /f "usebackq" %%a in (`mshta ^"javascript^:close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableMBytes ^)^);^"`) do set free_mem=%%a
echo %free_mem%
Code: Select all
@echo off
for /f "usebackq" %%a in (`mshta ^"javascript^:code^(close^(new ActiveXObject^(^'Scripting.FileSystemObject^'^).GetStandardStream^(1^).Write^(GetObject^(^'winmgmts:^'^).ExecQuery^(^'Select * from Win32_PerfFormattedData_PerfOS_Memory^'^).ItemIndex^(0^).AvailableMBytes^)^)^); ^"`) do set free_mem=%%a
echo %free_mem%
pause
Code: Select all
chrome.exe 6604 Console 1 341,108 K
chrome.exe 4220 Console 1 74,548 K
chrome.exe 7256 Console 1 52,876 K
chrome.exe 8084 Console 1 35,156 K
vncviewer.exe 8056 Console 1 23,904 K
Code: Select all
C:\>ramall
>=1GB
3GB
3,693,816
3.6GB (rounded down)
3693816 KB
C:\>
Code: Select all
@echo off
setlocal enableextensions enabledelayedexpansion
:: look for gnuwin32, with cut(coreutils) , sed, and tail. and not windows's tail.
:: I put the 2>1 because in a test, tail.bat had the letters df in there which is a command in linux, in gnuwin32!
set error=false
:: @tail --version 2>1 | find /i "GNU" >nul
:: if %errorlevel%==1 set error=true
@cut --help >nul 2>nul
if NOT %errorlevel%==0 set error=true
@sed --help >nul 2>nul
if NOT %errorlevel%==0 set error=true
if %error%==true (
echo one of these isn't there. gnu tail,sed,cut. check that gnuwin32
echo is installed and coreutils package, and sed package, so you have
echo those three^(gnu tail,cut,sed^), and that they're in the path
set error=
exit /b
)
set error=
:: set pathofgnuwin32="c:\program files (x86)\gnuwin32\bin"
set tempfile1=%temp%\asdf1.a
set tempfile2=%temp%\asdf2.a
set tempfile3=%temp%\asdf3.a
set tempfile4=%temp%\asdf4.a
tasklist >%tempfile1%
type %tempfile1% | tail +4 > %tempfile2%
cut -b 68- %tempfile2% > %tempfile3%
sed -r "s/\d32|K|,//g" %tempfile3% >%tempfile4%
set total=0
for /f %%f in (%tempfile4%) do @(set /a total+=%%f)>nul
:: ------------
:: --- added this
set a=%total%
:: ----------------------------------------------------------------
if "%a:~-9,-6%"=="" echo ^< 1GB
if NOT "%a:~-13,-6%"=="" echo ^>=1GB
set yotta=%a:~-24,-21%
set zetta=%a:~-21,-18%
set exa=%a:~-18,-15%
set peta=%a:~-15,-12%
set tera=%a:~-12,-9%
set giga=%a:~-9,-6%
set mega=%a:~-6,-3%
set kilo=%a:~-3%
set prefix=
if NOT "!yotta!"=="" (
set yotta=!yotta!,
if "!prefix!"=="" (
set prefix=YB
echo !a:~-24,-21!!prefix!
)
)
if NOT "!zetta!"=="" (
set zetta=!zetta!,
if "!prefix!"=="" (
set prefix=ZB
echo !a:~-21,-18!!prefix!
)
)
if NOT "!exa!"=="" (
set exa=!exa!,
if "!prefix!"=="" (
set prefix=EB
echo !a:~-18,-15!!prefix!
)
)
if NOT "!peta!"=="" (
set peta=!peta!,
if "!prefix!"=="" (
set prefix=PB
echo !a:~-15,-12!!prefix!
)
)
if NOT "!tera!"=="" (
set tera=!tera!,
if "!prefix!"=="" (
set prefix=TB
echo !a:~-12,-9!!prefix!
)
)
if NOT "!giga!"=="" (
set giga=!giga!,
if "!prefix!"=="" (
set prefix=GB
echo !a:~-9,-6!!prefix!
)
)
if NOT "!mega!"=="" (
set mega=!mega!,
if "!prefix!"=="" (
set prefix=MB
echo !a:~-6,-3!!prefix!
)
)
if "!mega!"=="" (
if "!prefix!"=="" (
set prefix=KB
echo !kilo!
)
)
echo !yotta!!zetta!!exa!!peta!!tera!!giga!!mega!!kilo!
if "%prefix%"=="YB" echo !a:~-24,-21!.!a:~-21!YB (rounded down)
if "%prefix%"=="TB" echo !a:~-12,-9!.!a:~-9,1!TB (rounded down)
if "%prefix%"=="GB" echo !a:~-9,-6!.!a:~-6,1!GB (rounded down)
if "%prefix%"=="MB" echo !a:~-6,-3!.!a:~-3,1!MB (rounded down)
set a=
:: echo %a:~-13,-6%,%a:~-6,-3%,%a:~-3%
:: -----------------------------------------------------
echo %total% KB
set tempfile1=
set tempfile2=
set tempfile3=
set tempfile4=
Code: Select all
C:\blah>tasklist>a.a
C:\blah>del b.b
C:\blah>for /f "tokens=5 delims= " %f in (a.a) do @echo %f >>b.b
C:\blah>sed "s/,//" b.b>c.c
C:\blah>grep -P "^\d+" c.c>d.d
C:\blah>set total=0
C:\blah>for /f %f in (d.d) do @(set /a total+=%f)>nul
C:\blah>echo %total%
3699432
C:\blah>
Code: Select all
C:\blah>echo %total%
3699432
C:\blah>set /a totalmb=%total%/1024
3612
C:\blah>
Code: Select all
@Echo Off
SetLocal
For /F "Tokens=2 Delims==" %%A In (
'WMIc Path Win32_PerfFormattedData_PerfOS_Memory Get AvailableMBytes /Value'
) Do For %%B In (%%A) Do Set MBMFree=%%B
Echo=[%%MBMFree%%=%MBMFree%]
Pause>Nul
Code: Select all
@Echo Off
SetLocal
For /F "UseBackQ" %%A In (
`MsHTA ^"JavaScript:Code(close(new ActiveXObject('Scripting.FileSystemObject'^).GetStandardStream(1^).Write(GetObject('WinMgmts:'^).ExecQuery('Select AvailableMBytes From Win32_PerfFormattedData_PerfOS_Memory'^).ItemIndex(0^).AvailableMBytes^)^)^);^"`
) Do Set MBMFree=%%A
Echo=[%%MBMFree%%=%MBMFree%]
Pause>Nul
Code: Select all
@Echo Off
SetLocal
For /F %%A In (
'PowerShell -C (GWMI -Class Win32_PerfFormattedData_PerfOS_Memory^).AvailableMBytes'
) Do Set MBMFree=%%A
Echo=[%%MBMFree%%=%MBMFree%]
Pause>Nul
Code: Select all
@Echo Off
SetLocal
For /F "UseBackQ" %%A In (
`PowerShell -C "Get-Counter -Counter '\Memory\Available MBytes'|%%{$_.CounterSamples[0].CookedValue}"`
) Do Set MBMFree=%%A
Echo=[%%MBMFree%%=%MBMFree%]
Pause>Nul