Не видит ключ в реестре, хотя он присутствует - C#
Формулировка задачи:
Привет,у меня такая проблема,я в прогамме указываю один путь,где нужно создать ключ,а программа не создает ключ,оправдываясь тем что указаного мной католога не существует.
Кто нибудь знает с чем это связано?Спасибо заранее
using System;
using Microsoft.Win32;
namespace Reester
{
class Program
{
static void Main(string[] args)
{
RegCreatySubKey();
}
private static void RegCreatySubKey()
{
RegistryKey regKey = Registry.LocalMachine;
string[] shell = new[] { "SOFTWARE", "Microsoft", "Windows", "CurrentVersion", "Explorer", "CommandStore", "shell" };
string prog = "Programma";
1) using (regKey = Registry.LocalMachine.OpenSubKey(shell[0],true))// тут regKey равно{HKEY_LOCAL_MACHINE}
2) { //сдеть уже regKey равно {HKEY_LOCAL_MACHINE\SOFTWARE}
3) if (regKey != null)//и тут уже regkey равно Null.А дальше программа не идет.
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[1], true))
{
if (regKey != null)
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[2], true))
{
if (regKey != null)
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[3], true))
{
if (regKey != null)
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[4], true))
{
if (regKey != null)
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[5], true))
{
if (regKey != null)
{
using (regKey = Registry.LocalMachine.OpenSubKey(shell[6], true))
{
if (regKey != null)
{
regKey.CreateSubKey(prog);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}Решение задачи: «Не видит ключ в реестре, хотя он присутствует»
textual
Листинг программы
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell", true))
{
key.CreateSubKey("Programma");
}