Ho bisogno di un test di un tasto, impostare un tasto, e cancellare una chiave e in tutti i casi il percorso completo e il i valori di chiave potrebbero in realtà non esistono. Ho pensato che il comando possa conto che restituisce falso se fa parte del percorso non esiste e non esiste controllare e crea il percorso sul set se non esiste, ma che sembra non essere il caso.
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");
}
}
}
Quindi quello che mi piacerebbe sapere è il modo più pulito per gestire questo problema. Potrei scrivere una funzione rapida che rompe i percorsi up, prove di ogni livello, e aggiunge la sottochiave se non c'è già, ma non vorrei fare che se c'è un modo più elegante o un modo per farlo.