Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Force Vista Ready Boost

3.46/5 (13 votes)
21 Sep 2008CPOL2 min read 1   345  
Forces Vista ready boost on a specific removable drive

Introduction 

ReadyBoost is a technology built into Windows Vista that caches disk reads onto a flash memory device. It can work with USB memory keys, flash memory cards, such as SD and CompactFlash, and other types of flash devices. It caches all types of file reads, not just the working set, nor just DLLs or other persistent operating system data.

Note

ReadyBoost does not cache file writes—it's a write-through cache. That way, you never lose any precious data that's meant to be written to a hard drive. After all, a flash memory key can get yanked out of a system at any time. The cache itself is encrypted using AES-128 encryption, so no one can steal your flash memory key and casually browse through the cache file to see what you've been doing.

Background

According to Microsoft, the minimum requirements for a USB memory device to be ReadyBoost capable is 2.5MB/sec for 4K random access reads and 1.5MB/sec for 512K random writes—and that rate has to be achieved across the whole flash memory space. When you plug a USB memory device into the system, Vista actually does a performance check to see if the device meets the standard. Vista won't allow you to use a device and that's where this application was built. 

Overview

General questions regarding Microsoft ReadyBoost are answered by Matt Ayers from Microsoft can be found here.

You may also want to read about "Vista ReadyBoost or SnailBoost" here.

Using the Code

The code is mainly about finding and editing the Windows registry key of a certain removable drive and fake its read and write speed values:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;

namespace QForce_Ready_Boost
{
    public partial class Form1 : Form
    {        
        RegistryKey key;   
        public Form1()
        {
            InitializeComponent();
        }

        string[] arDrives;
        string strDrive;
        DriveInfo di;

        private void load_drivers()
        {
            try
            {
                combo_Drives.Items.Clear();
                arDrives = System.Environment.GetLogicalDrives();
                foreach (string strDriveName in arDrives)
                {
                    di = new DriveInfo(strDriveName);
                    if (di.DriveType == DriveType.Removable)
                        combo_Drives.Items.Add(di.VolumeLabel + 
			" (" + strDriveName.Replace("\\", "") + ")");
                }
                if (combo_Drives.Items.Count > 0 && combo_Drives.Text.Length == 0)
                    combo_Drives.Text = combo_Drives.Items[0].ToString();
            }
            catch (Exception)
            { }
        }

When you click the force button, the registry values for WriteSpeedKBs and ReadSpeedKBs are simply altered to ReadyBoost compatible values (10,000,000 in our case):

C#
private void btn_Force_Click(object sender, EventArgs e)
{
    try
    {
	di = new DriveInfo(combo_Drives.Text.Substring
			(combo_Drives.Text.Length - 3, 2) + "\\");

	string keyLocation = @"Software\Microsoft\Windows NT\CurrentVersion\
	EMDMgmt\_??_USBSTOR#Disk&Ven_&Prod_USB_DISK_2.0&Rev_PMAP#077C0EA5004B&0#
	{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" + strDrive + "_1078135262";

	key = Registry.LocalMachine.OpenSubKey(keyLocation, true);

	key.SetValue("ReadSpeedKBs", 10000000, RegistryValueKind.DWord);
	key.SetValue("WriteSpeedKBs", 10000000, RegistryValueKind.DWord);
	key.SetValue("PhysicalDeviceSizeMB",
		Math.Round(((double)di.TotalSize/1024)/1024) , 
		RegistryValueKind.DWord);
	key.SetValue("RecommendedCacheSizeMB", 
		Math.Round(((double)di.TotalFreeSpace / 1024) / 1024) / 2, 
		RegistryValueKind.DWord);
	key.SetValue("CacheSizeInMB", trackBar1.Value, RegistryValueKind.DWord);

	key.SetValue("HasSlowRegions", 00000000, RegistryValueKind.DWord);

	MessageBox.Show("Drive " + combo_Drives.Text + 
		"\nforced successfully!","Success",MessageBoxButtons.OK,
		MessageBoxIcon.Information);
    }
    catch (Exception ex)
    { 
	MessageBox.Show("Please select a valid drive", 
	"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    }

    btn_Force.Enabled = false;           
}
//By Muammar Yacoob

Points of Interest 

You may have noticed the strange looking name of the registry key including the removable drive name:

_??_USBSTOR#Disk&Ven_&Prod_USB_DISK_2.0&Rev_PMAP#077C0EA5004B&0#
{53f56307-b6bf-11d0-94f2-00a0c91efb8b}" <blink>+ strDrive +</blink>
"_1078135262";

Well, I just noticed that Vista is using it no matter what drive we used and used it as a constant in my code!  

Please tell me if it's different in your case, so we might come up with a new idea of detecting the changes.

History

  • 21st September, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)