Bir anahtarı test etmem, bir anahtar ayarlamam ve bir anahtarı temizlemem gerekiyor ve her durumda tam yol ve anahtar değerleri gerçekten mevcut olmayabilir. Komutların, yolun bir kısmı kontrolde mevcut değilse false döndürerek ve mevcut değilse setteki yolu oluşturarak bunu açıklayacağını düşündüm, ancak durum böyle değil gibi görünüyor.
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");
}
}
}
Bilmek istediğim, bu sorunu çözmenin en temiz yolu. Yolları parçalayan, her seviyeyi test eden ve zaten orada değilse alt anahtarı ekleyen hızlı bir işlev yazabilirim, ancak bunu yapmak için daha zarif veya yerleşik bir yol varsa bunu yapmamayı tercih ederim.