PageFile.sys batch script


  1. Posts : 21
    10
       #1

    PageFile.sys batch script


    Hello,
    I need help writing a batch script that would configure Windows Virtual Memory based on the amount of RAM installed

    If you have 4 GB of RAM, set virtual memory to 8 GB (Custom size: set both initial and maximum size to 8192)
    If you have 8 GB of RAM, set virtual memory to 16 GB (Custom size: set both initial and maximum size to 16384).
    If you have 16 GB of RAM, set virtual memory also to 16 GB (Custom size: set both initial and maximum size to 16384)
    If you have 32 GB of RAM, set virtual memory also to 8 GB (Custom size: set both initial and maximum size to 8192) just in case.

    This virtual memory setting forces specific software on many computers

    Thank you very much for help
      My Computer


  2. Posts : 456
    Windows 10
       #2

    Can you post your current code and what isn't working or don't you have anything at all?

    This could be of your interest:
    How to change virtual memory size on Windows 10 | Windows Central
      My Computer


  3. Posts : 21
    10
    Thread Starter
       #3

    I don't have the code because I haven't written anything in batch for several years

    I associate which registry key is responsible for a given function, but detecting the amount of memory is a bit more complicated
      My Computer


  4. Posts : 456
    Windows 10
       #4

    I think I can make a batch file like this. Does it matter if it would have to be run as admin?
    Also I don't know if I got your logic right, what about the values between this memory sizes?

    7 GB or less = Initial 8 GB - Max 8 GB
    8 GB - 31 GB = Initial 16 GB - Max 16 GB
    32 GB or More = Initial 8 GB - Max 8 GB

    Is that right?
      My Computer


  5. Posts : 21
    10
    Thread Starter
       #5

    ricardobohner said:
    I think I can make a batch file like this. Does it matter if it would have to be run as admin?
    Also I don't know if I got your logic right, what about the values between this memory sizes?

    7 GB or less = Initial 8 GB - Max 8 GB
    8 GB - 31 GB = Initial 16 GB - Max 16 GB
    32 GB or More = Initial 8 GB - Max 8 GB

    Is that right?

    That's exactly what the file is about

    any file i wont run with administrator privileges from old windows xp anyway
      My Computer


  6. Posts : 456
    Windows 10
       #6

    Made some testing with a computer with 6 GB and a computer with 12 GB, don't have a PC with 32 or more memory:



    Here is the code:

    Code:
    @echo off
    
    :: If you have 4 GB of RAM, set virtual memory to 8 GB (Custom size: set both initial and maximum size to 8192)
    :: If you have 8 GB of RAM, set virtual memory to 16 GB (Custom size: set both initial and maximum size to 16384).
    :: If you have 16 GB of RAM, set virtual memory also to 16 GB (Custom size: set both initial and maximum size to 16384)
    :: If you have 32 GB of RAM, set virtual memory also to 8 GB (Custom size: set both initial and maximum size to 8192) just in case.
    
    net session >nul 2>&1 || (powershell start -verb runas '"%~0"' &exit /b)
    for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"
    set /a Memory=0
    for /f "Delims=" %%a in ('wmic memorychip get capacity /value') do for /f "tokens=2 delims==" %%b in ("%%~a") do call :MemoryCalculator "%%~b"
    
    wmic computersystem where name="%computername%" set AutomaticManagedPagefile=false > nul 2> nul
    
    IF %Memory% LEQ 7 goto :7GBOrLess
    IF %Memory% LEQ 31 goto :8to31GB
    IF %Memory% GEQ 32 goto :32GBOrMore
    
    :7GBOrLess
    cls
    echo.
    echo  You have %Memory% GB of memory! Changing your Pagefile to Initial: 8 GB - Max: 8 GB ...
    timeout /t 5 > nul
    wmic pagefileset where name="C:\\pagefile.sys" set InitialSize=8192,MaximumSize=8192 > nul 2> nul
    goto :End
    
    :8to31GB
    cls
    echo.
    echo  You have %Memory% GB of memory! Changing your Pagefile to Initial: 16 GB - Max 16 GB ...
    timeout /t 5 > nul
    wmic pagefileset where name="C:\\pagefile.sys" set InitialSize=16384,MaximumSize=16384 > nul 2> nul
    Goto :End
    
    :32GBOrMore
    cls
    echo.
    echo  You have %Memory% GB of memory! Changing your Pagefile to Initial: 8 GB - Max 8 GB ...
    timeout /t 5 > nul
    wmic pagefileset where name="C:\\pagefile.sys" set InitialSize=16384,MaximumSize=8192 > nul 2> nul
    goto :End
    
    :End
    cls
    echo.
    echo  For the changes to take effect you must restart your computer!
    echo.
    echo  [R]estart now
    echo.
    echo  [L]ater
    echo.
    set /p "Option=%BS% Option: "
    IF /i "%Option%"=="R" shutdown -r -t 30
    exit
    
    :MemoryCalculator
    for /f "Delims=" %%a in ('powershell %1 /1024 /1024 /1024') do set /a Memory=%Memory% + %%a
    goto :EOF
      My Computer


  7. Posts : 5,328
    Windows 11 Pro 64-bit
       #7

    With this batch script you can set virtual memory size to a static amount twice the installed RAM size.
    PageFile.sys batch script Attached Files
      My Computer


  8. Posts : 30
    Windows 10 enterprise
       #8

    You don't really want to run unsigned scripts or certificates up to 2025 that are not microsoft
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:08.
Find Us




Windows 10 Forums