Potrebujem na testovanie tlačidlo, nastavte kľúč, a vymaž kľúč a vo všetkých prípadoch celú cestu a kľúčové hodnoty nemusí v skutočnosti neexistuje. Myslel som si, že príkazy by predstavujú, že vrátením false, ak je časť cesta neexistuje na kontrolu a vytvoriť cestu na súbor, ak je to neplatili, ale že sa zdá, že nie je prípad.
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");
}
}
}
Takže to, čo by som chcel vedieť, je najčistejší spôsob, ako zvládnuť tento problém. Mohol by som napísať rýchly funkciu, ktorá rozbije cesty nahor, testy každej úrovni, a dodáva registry, ak tam ešte nie je, ale radšej by som to urobiť, že ak tam je viac elegantné alebo vstavaný spôsob, ako to urobiť.