1

I want set default icon of some extension by C#. But this gives me error -> Security Exception was unhandled

RegistryKey FileExt = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes", RegistryKeyPermissionCheck.ReadWriteSubTree);

How can I do that?

tshepang
  • 12,111
  • 21
  • 91
  • 136
sczdavos
  • 2,035
  • 11
  • 37
  • 71

4 Answers4

1

Maybe the user you are using to log in on the machine does not have privileged to access or modify the registry. try run the code with administrator account and see what happens. also if there is no user logged in the same error maybe occurs for instance check this.

Community
  • 1
  • 1
Jalal Said
  • 15,906
  • 7
  • 45
  • 68
1

try to run your application as administrator.

maniacneron
  • 424
  • 6
  • 19
0

I presume this is on Windows Vista or 7.

You may need to have elevated privileges to change some values in the registry. Even a user with administrative privileges will get the UAC pop up to ask permission before a program can do this.

Have a look at a question about this.

Here is a codeproject article about gaining elevated privileges.

Community
  • 1
  • 1
iandotkelly
  • 9,024
  • 8
  • 48
  • 67
0

try this method instead of yours:

public RegistryKey OpenSubKey(
    string name,
    bool writable
)

Maybe a true is enough ;-)

Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes", true);
MariusK
  • 537
  • 5
  • 20