Why doesn't this work? I am trying to create a registry key under [HKEY_LOCAL_MACHINE\SOFTWARE\MyService], but nothing is created.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Win32;
namespace RegistryKey
{
class Program
{
static void Main(string[] args)
{
const string SUB_KEY_NAME = @"SOFTWARE\MyService";
// Create a subkey named MyService under HKEY_LOCAL_MACHINE.
Registry.LocalMachine.CreateSubKey(SUB_KEY_NAME);
}
}
}
Update: Never mind. I'm an idiot. I used the Remote registry Editor to inspect the registry in the belief that it would show the same as regedit. It didn't! I can see the path using regedit.
Best Answer
You don't have write access to HKLM. If you want to write here then you need to either: