我正在尝试修改我被告知控制是否在特定硬盘驱动器上启用写缓存的注册表项。关键应该是:HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum\IDE\<DiskName>\<SerialNo>\Device Parameters\Disk\UserWriteCacheSetting
但是,在尝试创建此密钥时我一直遇到问题(因为默认情况下它不存在)。如果我尝试打开...\Device Parameters\Disk\
具有写入权限的权限,则会收到 SecurityException 错误;“不允许请求的注册表访问”。现在我已将<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
标志添加到我的清单文件中,以确保我具有管理员访问权限,但我仍然没有任何运气。
任何想法都会很棒!
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;
}