Creating new Ramdisks Programatically with Imdisk
For a while now I have used Imdisk to create ramdisks to store data temporarily while I experiment with it. Imdisk is a driver for windows systems that allows you to create virtual drives that are stored either in memory, or in a file on your hard drive. It also allows you to mount existing images stored in iso
or img
files to let you explore their contents, for example.
Since I use ramdisks so often, I have written a batch script that automates the process of creating a ramdisk, and I thought that I would share it here:
@echo off
:: BatchGotAdmin7
:: From http://stackoverflow.com/a/10052222/1460422
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
echo Ramdisk creation script
title Ramdisk Creation
set /p drive_letter=Enter Drive Letter:
if "%drive_letter%"=="" ( set drive_letter=R )
if exist %drive_letter%: (
echo A disk already exists with the letter %drive_letter%:.
echo Please unmount it before using this script.
)
set /p size=Enter Size:
imdisk -a -s %size% -m %drive_letter%: -p "/fs:fat32 /q /y"
pause
( Pastebin, Raw, Size: 1.16KB )
To use it, first enter the driver letter that you want to assign to the new ramdisk, and then type in the size of ramdisk you want it to create, for example 512M
, or 1G
. Make sure you don't pick a number that is close to or above the total amount of ram you have in your system! Imdisk grabs all the RAM it will need for the ramdisk in advance!