HKEY_CLASSES_ROOT\Directory\Background\shell to define the menu item and its associated action.
Understanding the Registry Structure
The Windows shell uses the registry to determine what options appear when you right-click on desktop backgrounds or within Explorer folders. To add a persistent item outside of the "New" menu, you must target theBackground subkey under Directory. This ensures the option appears both on the desktop and inside folder views. The structure requires a parent key for the shell command, a subkey for the default icon, and a crucial command subkey that defines the executable behavior. Without this precise hierarchy, the context menu item may fail to launch or disappear after a system restart.
Creating the Registry Entry
You can achieve this by using the Registry Editor or by importing a prepared.reg file. The following steps outline the manual method using the built-in regedit tool, which gives you full control over the configuration.
- Open Registry Editor: Press
Win + R, typeregedit, and press Enter. Confirm any User Account Control prompts. - Navigate to the Path: Go to
HKEY_CLASSES_ROOT\Directory\Background\shell. If theshellkey does not exist, create it. - Create the Menu Item: Right-click on
shell, selectNew > Key, and name itAddTextDoc. This internal name identifies the command. - Set the Display Name: With
AddTextDocselected, click on the(Default)value on the right pane. Change its data to&New Text Document. The ampersand (&) before 'N' enables keyboard shortcuts (Alt+N). - Add an Icon (Optional): Right-click
AddTextDoc, selectNew > Key, and name iticon. Set its default value to%SystemRoot%\system32\notepad.exeto give the menu item a recognizable Notepad icon. - Define the Command: Right-click
AddTextDocagain, selectNew > Key, and name itcommand. This is the most critical step for functionality.
Configuring the Correct Command Value
Many online guides provide incorrect commands that fail because they do not correctly pass the current working directory. The previous error occurred because environment variables like%TEMP% resolve to the user's temporary folder, ignoring the location where the user clicked. Furthermore, using %1 in a background context is unreliable because the background selection does not always populate the first argument index correctly.
To fix this, you must use the %V variable, which specifically represents the path of the folder where the context menu was invoked.
- Select the
commandkey you created in the previous section. - In the right pane, double-click the
(Default)value. - Enter the following string exactly:
cmd /c echo. > "%V\New Text Document.txt"
cmd /c: Runs the command in a new command prompt window and closes it immediately after execution.echo.: Outputs a blank line, effectively creating an empty file stream.> "%V\New Text Document.txt": Redirects that output into a new file named "New Text Document.txt" in the directory represented by%V.
echo. is preferred over opening Notepad because it is instantaneous and does not require launching a separate application. If you prefer to open Notepad with the new file, you can use: notepad "%V\New Text Document.txt". However, this will leave an empty Notepad window open, whereas the cmd approach creates the file silently.
Alternative Method: Using a .reg File
For users who prefer a faster setup or want to automate deployment across multiple machines, you can save the following content asadd_text_doc.reg and double-click it to import.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddTextDoc]
@="&New Text Document"
[HKEY_CLASSES_ROOT\Directory\Background\shell\AddTextDoc\command]
@="cmd /c echo. > \"%V\\New Text Document.txt\""
Note the escaped quotes (\") around %V. This ensures that if your folder path contains spaces, the command executes correctly. After importing, you may need to restart Explorer or log out and back in for the change to take effect. You can quickly restart Explorer by opening Task Manager, finding explorer.exe, and selecting Restart.
Removing the Entry
If you wish to revert the changes, simply delete theAddTextDoc key located at HKEY_CLASSES_ROOT\Directory\Background\shell. Alternatively, you can create another .reg file with the following content to automatically remove it.
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\Background\shell\AddTextDoc]
Windows 11: Using Shortcuts for Context Menu Items provides additional context on how modern Windows versions handle shell extensions, which may help if you encounter issues with third-party tools interfering with this native registry modification.
Frequently Asked Questions
Why doesn't the file appear immediately after clicking?
The file is created instantly, but Windows Explorer might not refresh the view automatically. Press F5 to refresh the folder or desktop view, and the new "New Text Document.txt" file should appear. If it still does not show, ensure that hidden files are not being filtered out in your View settings.
Can I customize the filename generated by this command?
Yes, modify the command value in the registry. Replace "New Text Document.txt" with your desired name, such as "Readme.txt". However, note that every click will overwrite the same filename if it already exists in that directory, so consider adding a timestamp if you need unique names.
Will this work on Windows 11?
Yes, this registry modification works on Windows 10 and Windows 11. While Windows 11 changed the default context menu appearance, the underlying shell keys remain compatible. You may see the classic context menu or the simplified one depending on your system settings, but the custom entry will function in both.
Is it safe to edit the HKEY_CLASSES_ROOT key?
Editing HKEY_CLASSES_ROOT is generally safe for this specific operation because it redirects to HKEY_CURRENT_USER\Software\Classes for most user-level modifications. However, always back up your registry before making changes. Use File > Export in Regedit to save a backup of the entire hive or just the specific key you are modifying.
How do I make the file open in Notepad instead of just creating it?
Change the command value to notepad "%V\New Text Document.txt". This will create the file if it does not exist and immediately open it in Notepad for editing. This is useful if you frequently start drafting documents from the desktop, though it leaves the Notepad window open until you close it.