approximate logical structure of script:
1. detecting ram value (via wmic or smth else)
2. making actions depending upon ram value
2.1. if ram value less than 512mb than "regedit /s slowcfg.reg"
2.2. if ram value equals or more 512mb but less 1024mb than "regedit /
s normcfg.reg"
2.2. if ram value equals or more 1024mb than "regedit /s fastcfg.reg"
You are half way there ;-)
start with
wmic computersystem GET TotalPhysicalMemory
parse the output with for /f and decide with if-statements,
calculate the mb by dividing bytes two times through 1024 with set /a
For help on details see:
for /?
if /?
set /?
--
Regards
Matthias
You can reduce the output down to two lines by using the program's
filter
psinfo physical
(the line preceding the "Physical memory" line is
System information for \\PCNAME:
)
which is equipped with 6GB DDR3
I just verified with the very last version v1.75, but still the same
erroneous result.
--
Regards
Matthias
Ah - my XP box gives the correct 1024 MB result.
That's very annoying...
thank you.
would you mind to explain how to "parse the output with for /f " to
extract the ram value to some variable?
>> > how to detect installed to system memory (mb) and use this value in
>> > script for making various actions (e.g. for applying different
>> > configuration presets)?
>>
>> > approximate logical structure of script:
>> > 1. detecting ram value (via wmic or smth else)
>> > 2. making actions depending upon ram value
>> > 2.1. if ram value less than 512mb than "regedit /s slowcfg.reg"
>> > 2.2. if ram value equals or more 512mb but less 1024mb than "regedit /
>> > s normcfg.reg"
>> > 2.2. if ram value equals or more 1024mb than "regedit /s fastcfg.reg"
>>
>> You are half way there ;-)
>> start with
>> wmic computersystem GET TotalPhysicalMemory
>> parse the output with for /f and decide with if-statements,
>> calculate the mb by dividing bytes two times through 1024 with set /a
>thank you.
>would you mind to explain how to "parse the output with for /f " to
>extract the ram value to some variable?
@echo off
for /f %%a in (
'wmic computersystem GET TotalPhysicalMemory'
) do set "mem=%%a"
set mem=%mem:~0,-6%
if %mem% LSS 512 set file=regedit /s slowcfg.reg
if %mem% GTR 500 if %mem% LSS 1030 set file=regedit /s normcfg.reg
if %mem% GTR 1000 set file=regedit /s fastcfg.reg
echo %file%
pause
--
Regards,
Mic
All the best, Timo
--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.php
>@echo off
>
>for /f %%a in (
>'wmic computersystem GET TotalPhysicalMemory'
>) do set "mem=%%a"
>
>set mem=%mem:~0,-6%
>
>if %mem% LSS 512 set file=regedit /s slowcfg.reg
>if %mem% GTR 500 if %mem% LSS 1030 set file=regedit /s normcfg.reg
>if %mem% GTR 1000 set file=regedit /s fastcfg.reg
>
>echo %file%
>
>pause
The numbers will have to be checked on machines with different ram as I
made ballpark guesses about the figures returned.
--
Regards,
Mic
thank you, that works!
i just have tested on my machine with 2gb ddr ram (windows xp pro sp3)
and got the result 2146.
several experiments on different machines (windows xp pro sp3) showed
that wmi returnes 536 for 512mb, 1072 for 1024mb, 2146 for 2048mb.
I was going to suggest that, but there was a clue in the original post
that led me to think the scheme had to be portable, and current versions
of his tools pop up a dialog box and make a registry entry the first time
they are used on a machine. It can be faked by forcing the registry entry
before invoking the utility, but that doesn't feel right.
--
Ted Davis (tda...@mst.edu)
What about using the registry and a simple calculation, it may not be the
most accurate method but should be enough to make an informed decision (and
it's portable)
::----- START -----
@ECHO OFF & SETLOCAL ENABLEDELAYEDEXPANSION
SET KEY="HKLM\HARDWARE\RESOURCEMAP\System Resources\Physical Memory"
FOR /F "TOKENS=3" %%# IN ('REG QUERY %KEY% /V .Translated^|FIND "REG_"')
DO (
SET Val=%%#)
SET "HS=%Val:~-8%"
SET/A "HP1=(0x%HS:~1,1% / 1048576) + (0x%HS:~0,1% / 65536)"
SET/A "HP2=(0x%HS:~3,1% / 4096) + (0x%HS:~2,1% / 256)"
SET/A "HP3=(0x%HS:~5,1% / 16) + (0x%HS:~4,1%)"
SET/A "HP4=(0x%HS:~7,1% * 16) + (0x%HS:~6,1% * 256)"
SET/A "MemMb=%HP1% + %HP2% + %HP3% + %HP4%"
ECHO= Installed RAM: %MemMb% Mb
>NUL PING -n 6 127.0.0.1
::------ END ------
HI Alex,
the problem is that batch integers are limited to 32bit accuracy incl.
sign giving a maximum of 2GB.
Since wmic output is in decimal bytes and the last 6 places a
truncated, the exact values of MB (1024*1024) and GB (1024*1024*1024)
can't be matched.
--
Regards
Matthias
The ENABLEDELAYEDEXPANSION is not required.
My german Win7 returns:
Gesamter physikalischer Speicher: 6.134 MB
--
Regards
Matthias
thank you for this interesting alternative but calculations dont seem
to be so simple at least from the first glance... and i think these
are very much operations including working with system registry. if it
really could work faster than the following code its possible for this
interesting alternative to have sense in some cases:
::
@echo off
for /f %%a in ('wmic computersystem GET TotalPhysicalMemory') do set
"mem=%%a"
set mem=%mem:~0,-6%
echo %mem%mb is installed
if %mem% LSS 536 echo slow machine
if %mem% GTR 536 if %mem% LSS 1072 echo normal machine
if %mem% GTR 1072 echo fast machine!
pause
::
> thank you for this interesting alternative but calculations dont seem
> to be so simple at least from the first glance... and i think these
> are very much operations including working with system registry. if it
> really could work faster than the following code its possible for this
> interesting alternative to have sense in some cases:
I'm not sure that I understand.
I've already done the calculations; How much more simple can it get!
How fast does it need to be? It returns a result on my machines almost
instantaneously!
Not only have I never seen this method used, it will also work in more
situations, since WMIC is not as readily available.
i tried these lines inside cmd-file (copy-paste) and got the message
"the syntax of command line is incorrect" with instant closing of cmd
window.
>> Not only have I never seen this method used, it will also work in more
>> situations, since WMIC is not as readily available.
> i tried these lines inside cmd-file (copy-paste) and got the message
> "the syntax of command line is incorrect" with instant closing of cmd
> window.
His solution works just fine. You probably got caught with the wraps.
Well not overall.
On my Win7-64bit the referenced Key has a different structure,
the last 8 places are all zero.
Otherwise a nice solution.
--
Regards
Matthias