我需要测试一个关键,设置一个关键,并明确一个关键和在所有情况下的全的道路和关键的价值观可能实际上不存在。 我认为该指令会考虑,通过返回假,如果一部分的道路并不存在对检查和创建的道路上设置的,如果它不存在,但这似乎不是这种情况。
internal bool DownloadGroupByOff()
{
using (RegistryKey hku = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
using (RegistryKey explore = hku.OpenSubKey(@"Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{885A186E-A440-4ADA-812B-DB871B942259}"))
{
if (GetValueInt(explore,"GroupView") == 0)
return true;
}
}
return false;
}
public void DownloadGroupByEnable()
{
using (RegistryKey hku = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
using (RegistryKey explore = hku.OpenSubKey(@"Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{885A186E-A440-4ADA-812B-DB871B942259}", true))
{
explore.DeleteValue("GroupView");
explore.DeleteValue("Mode");
}
}
}
public void DownloadGroupByDisable()
{
using (RegistryKey hku = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
{
using (RegistryKey explore = hku.OpenSubKey(@"Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{885A186E-A440-4ADA-812B-DB871B942259}", true))
{
explore.SetValue("", "Downloads");
explore.SetValue("GroupView", "0");
explore.SetValue("Mode", "4");
}
}
}
所以我想知道的是最清洁的方式来处理这个问题。 我可以写一个快速的功能,打破的路径,测试每个级别,并增加了子项,如果它不在那里了,但是我宁愿不这样做,如果有一个更优雅的或建造的方式这样做。