Click here to Skip to main content
15,885,044 members
Articles / Programming Languages / C#
Article

Accessing '(Default)' Key in Registry OR 'MyComputer' Hotkey

Rate me:
Please Sign up or sign in to vote.
3.21/5 (6 votes)
15 Nov 2007Ms-PL3 min read 52.7K   710   8  
An article on 'Modifying '(Default)' Registry key value
Screenshot - hotkey.jpg

Introduction

Every article on 'Registry' describes how to change/modify the 'named' registry keys (say, 'PaintDesktopVersion' key in HKEY_CURRENT_USER\Control Panel\Destop). But no article mentions how to access or modify the '(Default)' registry key.

In most cases you can access the registry keys by simply specifying the name of the key. However, the approach is quite different while you are accessing the '(Default)' registry key that is created by the Operating System itself.

The '(Default)' registry key can be represented by empty double-quotes(""), without any white-space inbetween.

That means wherever you want to access the '(Default)' registry key; represent it as empty double-quotes instead of specifying by name. Moreover, you will get an error message if you try to access/modify the '(Default)' registry key via the name itself.

Thats the reason, I'm writing this article. This article shows how to modify the '(Default)' registry key by enabling a hotkey — Yes! a hotkey for 'MyComputer'.

Once you run this application, your default 'Explorer Window' hotkey 'Win + E' will be assigned to 'MyComputer'. Also, if you wish to remove the hotkey, then you can rollback the effect by simply re-runnung the application.

About Modifying Registry

The Windows registry is a database which stores settings and options for the operating system for Microsoft Windows. The registry contains the configuration information.

As mentioned, the registry is a very sensitive part of Operating System. So you cannot directly modify registry key values through your programming codes. Moreover, you require administrative privileges to do so. To access Registry include the 'Microsoft.Win32' namespace, in your project.

To access the registry key, create an object of 'RegistryKey' class. Now assign that object which registry location you are accessing. Keep in mind that, at the time of specifying the registry location that you want to access, you've to explicitly specify whether you are accessing the registry for reading purposes or for writing purposes via a bool value (TRUE -> Write, FALSE -> Read). By default, permission will be set for reading only.

C#
string root = "Folder\\shell\\explore\\ddeexec";
RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(root, true);

To modify the registry value, you have to set the 'writable' permission to true, while opening a sub-key. Otherwise, you be only having the previlege to read from the regsitry, but no writing permission. (Don't bother about the 'writable' permission, just look into the code that i'd mentioned above or below. All your doubts will be solved.).

Using the code

This article handles registry keys. So, don't forget to include the 'Microsoft.Win32' namespace. Now, navigate to location: 'HEKY_CLASS_ROOT\Folder\shell\explore\ddexec'. There are two keys in that location. They are:

  1. (Default)
  2. NoActivateHandler

By default the value of the '(Default)' key is:

(Default) ---> [ExploreFolder("%l", %I, %S)]

This is the registry view before enabling hotkey (ie, the default view):

Screenshot - BeforeModify.jpg

The key-value 'ExploreFolder(...)' makes the 'Win + E' hotkey open 'Explorer window'. To re-assign the hotkey to 'MyComputer' you have to change the 'Explore' term of 'ExploreFolder(...)' to 'ViewFolder(...)'. Don't bother about the arguments inside the parameters, just keep it as it is & ONLY replace the 'Explore' term to 'View'.

The below mentioned code enables the 'Win+E' hotkey to 'MyComputer'.

C#
string root = "Folder\\shell\\explore\\ddeexec";

RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(root, true);
rKey.SetValue("", "[ViewFolder(\"%l\", %I, %S)]");
rKey.Close();

This is the registry view after enabling hotkey:

Screenshot - AfterModify.jpg

You can reset the hotkey to 'Explore Window' by changing the value of '(Default)' key from 'ViewFolder(...)' to 'ExploreFolder(...)'. The code sample looks like this:

C#
string root = "Folder\\shell\\explore\\ddeexec";

RegistryKey rKey = Registry.ClassesRoot.OpenSubKey(root, true);
rKey.SetValue("", "[ExploreFolder(\"%l\", %I, %S)]");
rKey.Close();

History

Original Version : NOV 14, 2007

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
Software Developer (Junior)
India India
I'm an software engineer from India. I'm a big fan of Microsoft, the only genuine reason why I came to .NET technologies. And above all, C# always drives me wild...& i always spends my free time with C#.

Comments and Discussions

 
-- There are no messages in this forum --