2

How would I achieve what is shown in the image below? Assume the first 3 items are text files each using different text file templates and the 4th item is one not using a template i.e. just a blank text file. Note that txt is only an example and I would like to expand this to other file extensions.

enter image description here

This problem was not solved by any of the answers in How can I add an item to the 'new' context menu?, so I made a new question as suggested.

A file (a.txt) was created and placed in C:\WINDOWS\SHELLNEW. Then the tests below were performed.

Using this code would result in creating a file with the .000 extension and not txt.

Windows Registry Editor Version 5.00

; new file type
[HKEY_CLASSES_ROOT\.000]
@="000"

; template
[HKEY_CLASSES_ROOT\.000\ShellNew]
"FileName"="a.txt"

; file type name
[HKEY_CLASSES_ROOT\000]
@="Test"

Adding a FileName key to the .txt reg key only allowed 1 template to be used since it only allowed a path to 1 file.

[HKEY_CLASSES_ROOT\.txt\ShellNew]
"FileName"="a.txt"

Using this code added a context menu item but it did not use the specified template and context menu name.

Windows Registry Editor Version 5.00

; new file type
[HKEY_CLASSES_ROOT\.000]
@="textfile"

; template
[HKEY_CLASSES_ROOT\.000\ShellNew]
"FileName"="a.txt"

; file type name
[HKEY_CLASSES_ROOT\000]
@="Test"

Using this code would result in no context menu item to appear.

Windows Registry Editor Version 5.00

; new file type
[HKEY_CLASSES_ROOT\.000]
@="txt"

; template
[HKEY_CLASSES_ROOT\.000\ShellNew]
"FileName"="a.txt"

; file type name
[HKEY_CLASSES_ROOT\000]
@="Test"

1 Answer 1

1

I have a way to do this which is the following. I assume that you want two templates for .txt files: one "default" template, and a second one which i'll call the "script template". I think that you can adapt to your own needs.

Write a .reg file containing (adapted from here):

; ------- .txt default ----------
; new file type
[HKEY_CLASSES_ROOT\.txt]
@="txt"

; template
[HKEY_CLASSES_ROOT\.txt\ShellNew]
"FileName"="C:\\Path\\to\\your\\template.txt"

; file type name
[HKEY_CLASSES_ROOT\txt]
@="Text File"

; ------- .txt script ----------
; new file type
[HKEY_CLASSES_ROOT\.script.txt]
@="script.txt"

; template
[HKEY_CLASSES_ROOT\.script.txt\ShellNew]
"FileName"="C:\\Path\\to\\your\\template_script.txt"

; file type name
[HKEY_CLASSES_ROOT\script.txt]
@="Script text File"

Basically we create a fake extension .script.txt and a template for it.

The only drawback of this method is that your newly created script file will be named New Script text File.script.txt, with this extra .script that you might not want. But since the extension ends with .txt, the files created that way will be opened with whatever program associated with the .txt extension.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .