Help - Search - Members - Calendar
Full Version: RAMSize Lives!?
The CD Forum > Bart's PE Builder > Plugins
cquirke
I can't find the nice GUI version, and haven't got into PreShell, so I was still using the old batch file to set the RAM size in nu2menu-based Bart. I tarted it up a bit, but haven't tested it via Bart boot Autorun, as I don't use it there...
CODE
@Echo Off
:: just a simple batch file created by CWorks, edited by cquirke
:: 0x100000 = 1M
:: 0x20000000 = 512M

SetLocal

If "%ramdrv%"==""               Exit /b 4
If Not Defined ramdrv           Exit /b 3
If Not Defined ramdrv           Exit
If Not "%SystemDrive%"=="%~d0"  Exit /b 2
If "%SystemDrive%"=="C:"        Exit /b 1

Set Dec=%1
If Not "%1"=="" GoTo SkipMenu

:Menu
 Title=[ RAM Disk ] Choose Size
 Color 70
 Cls
 Echo.
 Set Dec=
 Set /P Dec=   Enter desired RAM disk size in Megs (or W to wipe):
:SkipMenu
 If /I "%Dec%"=="W"    GoTo Wipe
 If Not "%Dec:~4%"=="" GoTo Menu
 Set Test=%Dec%
 :Check
   Set Digit=%Test:~0,1%
   Set Test=%Test:~1,4%
   Set Hex=N
   For %%n In (0 1 2 3 4 5 6 7 8 9) Do (
     If "%Digit%"=="%%n" Set Hex=Y
   )
   If "%Hex%"=="N"     GoTo Menu
 If Not "%Test%"==""   GoTo Check
 Set Test=%Dec%
 Set Hex=h
 :Next
   Set /A Left=Test/16
   Set /A Digit=Test-Left*16
   Set /A Test=Left
   If "%Digit%"=="15"  Set Digit=F
   If "%Digit%"=="14"  Set Digit=E
   If "%Digit%"=="13"  Set Digit=D
   If "%Digit%"=="12"  Set Digit=C
   If "%Digit%"=="11"  Set Digit=B
   If "%Digit%"=="10"  Set Digit=A
   Set Hex=%Digit%%Hex%
 If Not "%Test%"=="0"  GoTo Next
If "%Hex%"=="" GoTo Menu

:Apply
 Set Hex=0x%Hex:~,-1%00000
 Echo.
 Echo    RAM drive to be wiped and set to %Dec%M (%Hex%)
 REG.exe ADD HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Ramdriv\Parameters /f /v DiskSize /t REG_DWORD /d %Hex%
:Wipe
 Color 7C
 Echo.
 Title Initializing RAM drive...
 Echo Please wait while the RAM drive is initialized...
 Echo.
 %SystemRoot%\System32\Devcon disable ramdriv
 %SystemRoot%\System32\Devcon enable  ramdriv
 Echo.
 Echo ...OK
 Echo.
 Title Initializing RAM drive... done!
 Color 78
:End
EndLocal

Features are:
- can be driven via command line parameters (easier to GUI)
- accepts decimal size, e.g. 512 for 512M
- accepts W as parameter to wipe the RAM drive without resize
Ed_P
Nice script cquirke. I'm sure cworks is happy to know his work has found a good home. biggrin.gif

I'm using a modified version of solara's myself. I don't have the RAM your systems have. sad.gif

CODE
@ECHO OFF
:: solara  http://www.911cd.net/forums//index.php?showtopic=13442&view=findpost&p=85615
Title=[RamDrive] Clear-Resize
color 17
setlocal
FOR /F "tokens=2* delims=  " %%A IN ('REG QUERY "HKLM\System\CurrentControlSet\Services\Ramdriv\Parameters" /v DiskSize') DO SET DiskSize=%%B
Set RamDrive=Unknown
IF %DiskSize% == 0x200000 Set RamDrive=2 MB
IF %DiskSize% == 0x400000 Set RamDrive=4 MB
IF %DiskSize% == 0x800000 Set RamDrive=8 MB
IF %DiskSize% == 0x1000000 Set RamDrive=16 MB
IF %DiskSize% == 0x2000000 Set RamDrive=32 MB
IF %DiskSize% == 0x3000000 Set RamDrive=48 MB
IF %DiskSize% == 0x4000000 Set RamDrive=64 MB
IF %DiskSize% == 0x8000000 Set RamDrive=128 MB
:_Start
cls
ECHO.
ECHO   WARNING!! - Everything on the RamDrive will be lost!
ECHO   Make sure no programs are currently accessing the RamDrive.
ECHO.
ECHO   Current Size of Ramdrive %Temp%= %RamDrive%
ECHO.
ECHO   1. Clear only
ECHO   2. Resize to 2 MB
ECHO   3. Resize to 4 MB
ECHO   4. Resize to 8 MB
ECHO   5. Resize to 16 MB
ECHO   6. Resize to 32 MB
ECHO   7. Resize to 48 MB
ECHO   8. Resize to 64 MB
ECHO   9. Resize to 128 MB
ECHO   0. Exit
ECHO.
SET Choice=
SET /P Choice=  Enter Choice:
IF /I '%CHOICE%' GEQ 'a' GOTO _Start
IF /I '%Choice%'==''  GOTO _Start
IF /I '%Choice%'=='1' GOTO _Clear
IF /I '%Choice%'=='2' Set DiskSize=0x0200000
IF /I '%Choice%'=='3' Set DiskSize=0x0400000
IF /I '%Choice%'=='4' Set DiskSize=0x0800000
IF /I '%Choice%'=='5' Set DiskSize=0x1000000
IF /I '%Choice%'=='6' Set DiskSize=0x2000000
IF /I '%Choice%'=='7' Set DiskSize=0x3000000
IF /I '%Choice%'=='8' Set DiskSize=0x4000000
IF /I '%Choice%'=='9' Set DiskSize=0x8000000
IF /I '%Choice%'=='0' exit
GOTO _Begin

:_Clear
@Echo Off
echo.
echo BEFORE
dir %ramdrv%\
for /D %%f in (%ramdrv%\*) do ( if /i not "%%f" == "%ramdrv%\Documents And Settings" rmdir /s /q "%%f" )
del %ramdrv%\* /q 2>nul 1>nul
echo.
echo AFTER
dir %ramdrv%\
GOTO End

:_Begin
@Echo Off
ECHO.

rem Test for Sherpya's Firefox plugin
set XFireFox=N
if exist "%ramdrv%\Documents And Settings\Default User\Application Data\Mozilla\Firefox\profiles.ini" set XFireFox=Y

%SystemRoot%\system32\devcon disable ramdriv
if errorlevel = 1 goto _ERROR

Reg Add HKLM\System\CurrentControlSet\Services\RamDriv\Parameters /v DiskSize /t REG_DWORD /d %DiskSize% /f
ECHO.
ECHO Re-enabling RAM drive
%SystemRoot%\system32\devcon enable ramdriv

rem If Sherpya Firefox plugin used reload the Documents and Settings folder
if "%XFireFox%" == "N" GOTO End
echo Firefox Firestarter reinitiated.
start /wait %SystemDrive%\Programs\Firefox\FireStarter.exe
echo.
echo RAM drive change complete.
echo.
dir %ramdrv%
GOTO END

:_ERROR
echo.
Echo Unable to change size of RAM drive.
Echo Something is accessing the %ramdrv% drive.
pause
Exit

:End
echo.
echo Press any key to exit.
pause > nul
Exit
fafot
@cquirke
Look here SetRamDriveGui.
stuartr
QUOTE (fafot @ Sep 14 2005, 01:45 AM)
@cquirke
Look here SetRamDriveGui.
*



Appears your website is not up?
fafot
My website is up all the time but the program is not there. It is Frodo's one and I just enchanced it. If you will read the thread that I mentioned you will find the full program there and the only thing to do is compile it.
cquirke
QUOTE (Ed_P @ Sep 14 2005, 03:31 AM)
Nice script cquirke. I'm sure cworks is happy to know his work has found a good home.  :D I'm using a modified version of solara's myself.  I don't have the RAM your systems have.  :( 

Hey, I'm typically 64M to 512M tops, on what I have to Bart. But once you can accept arbitrary decimal values as input, there's no reason to limit as much. In practice, the registry entry FFFFs (maxes) halfway through the max number of decimal digits I allow; I think that's around 5G.

This code has some interesting bits I might try out, as in practice I find the .CMD I've used (original CWorks and my own) tend to leave the RAM drive dead after it is resized!

CODE
FOR /F "tokens=2* delims=  " %%A IN ('REG QUERY "HKLM\System\CurrentControlSet\Services\Ramdriv\Parameters" /v DiskSize') DO SET DiskSize=%%B

That's nice, though I'd use hex-to-decimal to derive the decimal size value to display, instead of looking for canned values. I'll show the relevant code later.
CODE
:_Clear
@Echo Off
dir %ramdrv%\
for /D %%f in (%ramdrv%\*) do ( if /i not "%%f" == "%ramdrv%\Documents And Settings" rmdir /s /q "%%f" )
del %ramdrv%\* /q 2>nul 1>nul
dir %ramdrv%\
GOTO End

I wonder; should I clear the RAM drive before I disable and re-enable it? If so, I'd use something like the above logic, except I'd worry about subdirs (For /R?) and "difficult" attributes (Attrib -s -h -r %ramdrv%\*.* /S).
CODE
%SystemRoot%\system32\devcon disable ramdriv
if errorlevel = 1 goto _ERROR
Reg Add HKLM\System\CurrentControlSet\Services\RamDriv\Parameters /v DiskSize /t REG_DWORD /d %DiskSize% /f
ECHO.
%SystemRoot%\system32\devcon enable ramdriv
This is interesting too, in that he sizes the drive after disabling it. I think the logic I re-use from CWorks first sets the RAM drive size, then disables it, then restarts it again. I might do some sort of...

Color 7C
Echo.
Echo Unable to disable RAM drive %ramdrv%! Please close any apps using it...
Echo.
Set TimeOut=1000
:Again
%SystemRoot%\system32\devcon disable ramdriv
If errorlevel = 0 GoTo _OK
Set /A TimeOut=TimeOut-1
If "%TimeOut%"=="0" GoTo _IGiveUp
GoTo Again

...stuff.

QUOTE
*

Oh, I nearly forgot... hex to decimal, right?
CODE
@Echo Off

SetLocal

Set Dec=0
Set Hex=%1
If Not "%Hex:~5%"=="" (
 Echo Number too big!
 EndLocal
 Exit /b 1
)
:Next
 Set Digit=%Hex:~0,1%
 Set Hex=%Hex:~1,5%
 Set Valid=N
 For %%n In (0 1 2 3 4 5 6 7 8 9 A B C D E F) Do (
   If /I "%Digit%"=="%%n" Set Valid=Y
 )
 If "%Valid%"=="N" GoTo Error
 Set /A Dec=Dec*16+Digit
If Not "%Hex%"==""  GoTo Next
Echo Hex %1 = Dec %Dec%
EndLocal
Exit /b 0

:Error
 Echo Invalid!
 EndLocal
Exit /b 2
Ed_P
@cquirke
QUOTE
This is interesting too, in that he sizes the drive after disabling it. I think the logic I re-use from CWorks first sets the RAM drive size, then disables it, then restarts it again. I might do some sort of...
The other scripts all assume that the disabling always occurs. I have found that not to be the case with my usage. Even a CMD window can impact the disabling. Thus I would end up with the Registry having one size for the RAM driver and the drive itself having something else. Not sure what would happen if either limit was actually exceeded and not really wanting to find out smile.gif I changed the logic to keep the two values in sync. A side benefit is solara's RAMDrive.cmd script always reports the correct size of the drive when run.

QUOTE
as in practice I find the .CMD I've used (original CWorks and my own) tend to leave the RAM drive dead after it is resized!

biggrin.gif biggrin.gif Yeah, that would be a downer. biggrin.gif Fortunately I haven't run into that one, yet. But I'm usually conservative in my allocations.

QUOTE
I wonder; should I clear the RAM drive before I disable and re-enable it?

I have not found that to be necessary. Many standalone utilities automatically test for the presence of their files on the RAM drive and auto reload them if not found. In that I frequently use Sherpya's Firefox I added it's RAM drive reload to my version of RAM Drive. I'm sure there are others and you can either tweak the script or put a reminder in the resizer's nu2menu to run the app's reload. That's what I did initially for FireStarter.

Changing the CMD window's color if there is an error is a good idea. If you use color a lot, or just don't like the default grey on black CMD window, you may find this script useful.

CMD_colors.cmd
CODE
@echo off&Title=CMD window color tester&MODE CON: COLS=71 LINES=24

set Xcolor=37

:START
Color  %Xcolor%
echo.
echo  Sets the default console foreground and background colors.
echo.
echo  COLOR [attr]
echo.
echo    attr        Specifies color attribute of console output
echo.
echo  Color attributes are specified by TWO hex digits -- the first
echo  corresponds to the background; the second the foreground.  Each digit
echo  can be any of the following values:
echo.
echo      0 = Black       8 = Gray
echo      1 = Blue        9 = Light Blue
echo      2 = Green       A = Light Green
echo      3 = Aqua        B = Light Aqua
echo      4 = Red         C = Light Red
echo      5 = Purple      D = Light Purple
echo      6 = Yellow      E = Light Yellow
echo      7 = White       F = Bright White
echo.
echo  Current window is COLOR %Xcolor%.
echo.
set Xcolor=
SET /P Xcolor= Enter COLOR BF attributes or null to exit:
if '%Xcolor%'=='' exit
cls
goto START
cool.gif
CWorks
QUOTE (cquirke @ Sep 15 2005, 04:29 PM)
  I think the logic I re-use from CWorks first sets the RAM drive size, then disables it, then restarts it again.


It doesn't matter if you do it before or after
the reg is only read when starting or restarting ramdriv

in other words you could delete the ram size from reg and ramdriv will still run just fine

I think the first version i did i disabled it first
but found it looked better to me with the disable and enable at the bottom

earliest version known to exist cool.gif
later I moved it here
and using reg files, how cheasy is that rolleyes.gif
didn't think anyone was using it so i never updated it except my own copy
Ed_P
@CWorks
QUOTE
the reg is only read when starting or restarting ramdriv

That is true for the driver, which is good, but not so for solara's RAMDrive script. It displays the RAM drive's current size by reading the Registry value. In order to change it's size it's good to know what it's current allocation is. smile.gif
cquirke
QUOTE (Ed_P @ Sep 17 2005, 01:32 AM)
@CWorks

That is true for the driver, which is good, but not so for solara's RAMDrive script.  It displays the RAM drive's current size by reading the Registry value.  In order to change it's size it's good to know what it's current allocation is.  smile.gif
*


Argh, this is driving me mad!! For some reason, my attempts to derive RAM drive size in decimal are failing, either because For /F is stripping leading zeros, and/or because my hex-to-decimal logic is buggy (tho it tested OK earlier). Gah!
CODE
@Echo Off

:: 0x100000 = 1M
:: 0x20000000 = 512M

GoTo Test

If Not Defined RAMDrv            Exit /b 1
If Not Exist %RAMDrv%\NUL        Exit /b 2

:Test
Reg Query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Ramdriv\Parameters /v DiskSize > %Temp%\RAMDSize.txt
If Not "%ErrorLevel%"=="0"       Exit /b 6
If Not Exist %Temp%\RAMDSize.txt Exit /b 5
For /F "tokens=2* delims=x" %%D In (%Temp%\RAMDSize.txt) Do Set RAMDrvSize=%%D
If Not "%RAMDrvSize:~10%"==""    Exit /b 3
Set Dec=0
Set Hex=%RAMDrvSize%


Echo %Hex%
Pause

:Next
 Set Digit=%Hex:~0,1%
 Set Hex=%Hex:~1,5%
 Set Valid=N
 For %%n In (0 1 2 3 4 5 6 7 8 9 A B C D E F) Do (
   If /I "%Digit%"=="%%n" Set Valid=Y
 )
 If "%Valid%"=="N"              Exit /b 4
 Set /A Dec=Dec*16+Digit
If Not "%Hex%"==""               GoTo Next
Set /A RAMDrvSize=Dec/4096
%~dp0\..\nu2menu\nu2menumsg.exe @SetEnvVar('RAMDrvSize',%RAMDrvSize%) @Reload
Exit /b 0
The above is GetSize.cmd, which is supposed to set environment variable RAMDrvSize to the size in decimal, and send this to nu2menu. It's to be used within this RAMSize.cmd
CODE
@Echo Off
:: just a simple batch file created by CWorks, edited by cquirke
:: 0x100000 = 1M
:: 0x20000000 = 512M

SetLocal

GoTo Test

If "%ramdrv%"==""               Exit /b 4
If Not Defined ramdrv           Exit /b 3
If Not Defined ramdrv           Exit
If Not "%SystemDrive%"=="%~d0"  Exit /b 2
If "%SystemDrive%"=="C:"        Exit /b 1

:Test
Set Dec=%1
If Not "%1"=="" GoTo SkipMenu

:Menu
 Title=Choose Size of RAM Drive %RamDrv%
 Call %~dp0GetSize.cmd
 Set Hex=%ErrorLevel%
 Color 70
 Cls
 Echo.
 If "%Hex%"=="0" (
   If Defined RAMDrvSize (
     Echo   RAM Drive %ramdrv% is currently %RAMDrvSize%M
   ) Else (
     Echo   RAM Drive %ramdrv% size is unknown; RAMDrvSize is not Set
   )
 ) Else (
     Echo   GetSize returned error %Hex%
 )
 Set Dec=
 Set /P Dec=   Enter desired RAM disk size in Megs (or W to wipe):
:SkipMenu
 If /I "%Dec%"==""     Exit /b 0
 If /I "%Dec%"=="X"    Exit /b 0
 If /I "%Dec%"=="W"    GoTo Wipe
 If Not "%Dec:~4%"=="" GoTo Menu
 Set Test=%Dec%
 :Check
   Set Digit=%Test:~0,1%
   Set Test=%Test:~1,4%
   Set Hex=N
   For %%n In (0 1 2 3 4 5 6 7 8 9) Do (
     If "%Digit%"=="%%n" Set Hex=Y
   )
   If "%Hex%"=="N"     GoTo Menu
 If Not "%Test%"==""   GoTo Check
 Set Test=%Dec%
 Set Hex=h
 :Next
   Set /A Left=Test/16
   Set /A Digit=Test-Left*16
   Set /A Test=Left
   If "%Digit%"=="15"  Set Digit=F
   If "%Digit%"=="14"  Set Digit=E
   If "%Digit%"=="13"  Set Digit=D
   If "%Digit%"=="12"  Set Digit=C
   If "%Digit%"=="11"  Set Digit=B
   If "%Digit%"=="10"  Set Digit=A
   Set Hex=%Digit%%Hex%
 If Not "%Test%"=="0"  GoTo Next
If "%Hex%"=="" GoTo Menu

:Apply
 Set Hex=0x%Hex:~,-1%00000
 Echo.
 Echo    RAM drive to be wiped and set to %Dec%M (%Hex%)
 REG.exe ADD HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Ramdriv\Parameters /f /v DiskSize /t REG_DWORD /d %Hex%
:Wipe
 Color 7C
 Echo.
 Title Initializing RAM drive...
 Echo Please wait while the RAM drive is initialized...
 Echo.
 %SystemRoot%\System32\Devcon disable ramdriv
 %SystemRoot%\System32\Devcon enable  ramdriv
 Echo.
 Echo ...OK
 Echo.
 Title Initializing RAM drive... done!
 Color 78
 Call %~dp0GetSize.cmd
:End
EndLocal

Both of these are looking a bit the worse for wear, having been abandoned midway through attempts to get this stuff to work. Here's the nu2menu logic...
CODE
DISABLED="@Or(@Not(@FileExists(@GetProgramDir(),@Not(@FileExists(@GetProgramDir())\..\ramsize\getsize.cmd))" CMD="RUN" FUNC="@GetProgramDir()\..\ramsize\ramsize.cmd">Set Size of RAM Disk @GetEnvVar('ramdrv') (@GetEnvVar('RAMDrvSize')M)</MITEM>
...which is an even less pretty sight. The idea is to have this in Bart with RAM drive running...

Set Size of RAM Disk B: (64M)

...and if not no item at all, a greyed-out...

RAM Disk is not running

...or...

RAM Disk B: Error!

...otherwise (e.g. pre-build menu testing, CD AutoRun, etc.)

I've looked for GUI alternatives, but either the site can't be found, and/or they are dependent on things I don't want to use, e.g. XPE, AutoIt, etc. So I press on.

As to the RAM drive failures that follow resizing, they do seem to be related to "in use" issues. Not so much that the drive needs to have all contents deleted, but that something such as a Servant Salamander window is holding the drive open. When this happens, the drive is not resized but appears to be writable; earlier I was getting failures on any attempts to write to the RAM drive if it had failed to resize.

One also needs a way to tell whether the RAM drive service is running, as simply reading a valid size value from the relevant registry location does not imply this.

BTW: What does a Bart boot do if a diskette drive B: exists?
Ed_P
QUOTE (cquirke @ Sep 17 2005 @ 10:21 AM)
One also needs a way to tell whether the RAM drive service is running, as simply reading a valid size value from the relevant registry location does not imply this.

If the RAMdisk plugin is Enabled it sets many entries in the Registry any of which could be tested for their presence. If found it indicates that the RAM drive is installed and would imply that it is running. Whether the size is valid depends on whose script is used to change it's value. smile.gif

If you mean running in the sense that it has been Disabled and the reEnable failed I don't know. Maybe checking the ControlSet001\Services\Ramdriv's Start value or the ControlSet001\Services\Ramdriv's ErrorControl value.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.