I am trying to modify a registry key that I have been told controls whether write-caching is enabled on particular hard drives. The key should be: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\IDE\<DiskName>\<SerialNo>\Device Parameters\Disk\UserWriteCacheSetting
However I keep having problems when trying to create this key (as it doesn't exist by default). If I try to open up the ...\Device Parameters\Disk\
with write access I get a SecurityException error; "Requested registry access is not allowed". Now I have added the <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
flag to my manifest file so as to ensure I have admin access, but I'm still not having any luck.
Any ideas would be great!
static void Main(string[] args)
{
RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Enum\\IDE\\");
foreach (string driveManafacturer in myKey.GetSubKeyNames())
{
RegistryKey driveKey = myKey.OpenSubKey(driveManafacturer);
foreach (string driveID in driveKey.GetSubKeyNames())
{
RegistryKey driveIDKey = driveKey.OpenSubKey(driveID, true);
string driveType = (string)driveIDKey.GetValue("Class");
if (driveType == "DiskDrive")
{
RegistryKey tempKey = driveIDKey.OpenSubKey("Device Parameters\\Disk\\", true);
if (tempKey == null)
{
tempKey = driveIDKey.CreateSubKey("Device Parameters\\Disk\\");
tempKey.SetValue("UserWriteCacheSetting", 0x0);
}
}
}
}
return;
}