0

I am having an issue with creating my Registry key. When I try to create it I get an error message saying: System.UnauthorizedAccessException: Access to the registry key 'HKEY_CLASSES_ROOT\PHPFiles' is denied. Here is the code:

var menuName = @"PHPFiles";
var command = @"PHPFiles\DefaultIcon";
RegistryKey regmenu = null;
RegistryKey regcmd = null;
try
{
    regmenu = Registry.ClassesRoot.CreateSubKey(menuName);
    if (regmenu != null)
        regmenu.SetValue("", "PHP Server Side Document");
    regcmd = Registry.ClassesRoot.CreateSubKey(command);
    if (regcmd != null)
        regcmd.SetValue("", @"C:RegistryIcons\PhpFile.ico");
}

How can I add my permissions to the registry code?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • 1
    Are you running as administrator? – Der Kommissar Apr 29 '15 at 18:46
  • I tried it but it does not work – Daniel Oviedomora Apr 29 '15 at 18:58
  • Are you running Visual Studio as an administrator when running this code? Or, another option, did you try to modify your settings so that the application always run as admin? See [this](http://stackoverflow.com/questions/2818179/how-to-force-my-net-app-to-run-as-administrator-on-windows-7). More specifically, the user account running this code must have permissions on the specified registry key (and below). – w128 Apr 29 '15 at 19:00
  • Also, you seem to be missing a backslash in this path: "C:RegistryIcons\PhpFile.ico" – w128 Apr 29 '15 at 19:02
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 29 '15 at 19:27

0 Answers0