var key = Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced");
key.SetValue("Hidden", 1);
Ah ha! Not quite as easy as I thought - this resulted in an exception
System.UnauthorizedAccessException was unhandled. Message="Cannot write to the registry key."
System.UnauthorizedAccessException was unhandled. Message="Cannot write to the registry key."
Luckily there is an overload for OpenSubKey that takes a boolean parameter called writable. So the following code works like a charm.
var key = Registry.CurrentUser.OpenSubKey(
@"Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced",
true);
key.SetValue("Hidden", 1);
No comments:
Post a Comment