Jump to content

- - - - -

A ImDisk wrapper batch to mount/unmount ad-hoc NTFS formated RAMDisks

  • Please log in to reply
4 replies to this topic

#1 LtPinback

  • Members
  • 2 posts

Posted 13 October 2013 - 02:20 PM

First I would like to thank Olof Lagerkvist for the ImDisk Virtual Disk Driver and v77 for the ToolKit both of which I use extensively.

For the creation of quick ad-hoc NTFS formated RAMDisks I have created the following batch script that may be also useful to others. Read the help text and source for a complete description. I have only tested it on Windows 8 Enterprise 64-bit but it should work on any  Windows 7 and Windows 8 system.








Help text:

A ImDisk wrapper batch to mount/unmount ad-hoc NTFS formatted RAMDisks in the
first available drive letter.
The program automatically detects privilege status and prompts user to elevate
it if needed. It also prompts for desired RAMDisk size in GB units (fraction
inputs are allowed. For example type "0.5" when prompted for size to create
a 500MB RAMDisk).

    RAMDISK [-m | -u | -d] /?

       -m    Mounts a NTFS formatted RAMDisk on the first free drive letter.
       -u    Unmounts last registered RAMDisk in the RAMDisk register file.
       -d    Deletes the RAMDisk register file.
       -?    Displays this help message.

The RAMDisk register file is stored on TEMP and works as a LIFO stack. Each
time the program is invoked with the -m switch a RAMDisk is created, mounted
and its drive letter is registered in the RAMDisk register file. Invoking the
program with the -u switch initiates a search for the last entry in the
RAMDisk register file and unmounts the RAMDisk corresponding to it and then
updates the RAMDisk register file accordingly.

The -d switch is provided because failure to properly unmount with the -u
switch mounted RAMDisks that were created with the -m switch will result in a
RAMDisk register file in an unsynchronized state. This most often occurs when
an user shutdowns the system before unmounting all ad-hoc RAMDisks (a frequent
occurrence due to the non persistent nature of such RAMDisks) or in the case of
unexpected system shutdown or in the case a mounted RAMDisk that was created
with the -m switch is unmounted via other methods (such as the IMDisk Toolkit's
RamDisk Configuration Tool).

As such it is recommended to include an entry in the system Task Scheduler to
run the program with the -d switch on system startup if TEMP resides in a
persistent location.

The recommended usage is to create two shortcuts. One invoking "RAMdisk -m" and
the other invoking "RAMdisk -u". Thus every time the first shortcut is launched
a new ad-hoc RAMDisk is created (after prompting user for privilege status and
size) and every time the second shortcut is launched the last created ad-hoc
RAMDisk is destroyed (again after prompting user for privilege status).

Edited by LtPinback, 13 October 2013 - 02:26 PM.

#2 v77


    Silver Member

  • Team Reboot
  • 553 posts

Posted 13 October 2013 - 03:33 PM

This looks interesting...

A little suggestion, though: if I understand, you are using a vbscript to display the list of the current drive letters. If you want to use WMI, you can also do it with a simple command like:
wmic logicaldisk get name
Another way would be to make a loop and to test each drive letter with a command like "if exist"...

Anyway, thanks for using ImDisk and for sharing this script. :hi:

#3 LtPinback

  • Members
  • 2 posts

Posted 13 October 2013 - 04:52 PM

I did try both of those solutions before settling out with the vbs solution.

wmic logicaldisk get name does not include the network shares mapped to drive letters and the "if exist" loop throws a popup warning error on drives that are mounted but not accessible like for example a smartphone connected to an usb for the sole reason to charge its battery.

#4 v77


    Silver Member

  • Team Reboot
  • 553 posts

Posted 13 October 2013 - 05:19 PM

wmic logicaldisk get name does not include the network shares mapped to drive letters


I forgot this issue, I had the same with the Toolkit...
A workaround could be to get the drive list before the privilege elevation, and register it for example in a temp file: in this case, these drives should appear in the list. At least, this worked for me.

#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 14387 posts
  • Location:The Outside of the Asylum (gate is closed)

Posted 13 October 2013 - 06:19 PM

There were some attempts in "pure batch", but I cannot remember if it takes care of network share (it should), in the worst case, instead of looping through the reduced list coming from mountvol, one could loop through all 26-2=24 letters.
The IF EXIST is not a problem (in the sense that there is a solution handy), using DIR which will not throw an error like IF EXIST :
and following.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users