I want set default icon of some extens开发者_StackOverflow中文版ion 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?
try to run your application as administrator.
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.
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.
try this method instead of yours:
public RegistryKey OpenSubKey(
string name,
bool writable
)
Maybe a true
is enough ;-)
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes", true);
精彩评论