../Msgboard/General customization/New Trick - Make new files with starting templateHome
Red - 13 Aug. 2003 - 09:21:

New Trick - Make new files with starting template

I've been wondering how they do it, and I finally figured it out. 8) Now I can create a new file from the new menu, and it will start off containing data of my choosing. This means code files can start with headers, image fiels can start with water marks, and files that can't start with zero bytes can now be used.

It's a two part edit: registry and file.

In the registry, under the extention you need to create a new key with the control it points to. For example: a .bat (batch file) has the text "batfile" in a text string. There is a matching key that tells windows what to do with that file. The new key would have to be under .bat and labeled "batfile" to work. Next you need yet another subkey called "ShellNew". In there you create a text string called "newfile" and a value of the file name of the template you want.

The second half is simple. Create a template file and place it in the hidden "c:\windows\shellnew" folder.

Now when you open the new submenu you can create (going with the eample) a new batch file with all the basic info one usually would need to redundantly type pre-existing.

Here is the registry key info:
REGEDIT4
[HKEY_CLASSES_ROOT\.bat\batfile\ShellNew]
"FileName"="start.bat"

Below is the code for a batch file installer to make the reg change and starter batch file.
 
13 Aug. 2003 - 09:23 Red
@echo off
:Coder: CutTheRedWire
:Date: 2003/8/12
:About: Adds a batch file entry to the "New File" menu with a custom template too


:REG FILE
:Create the registry file to be merged.
set newfile=%temp%\NewFile.reg
echo REGEDIT4>%newfile%
echo [HKEY_CLASSES_ROOT\.bat\batfile\ShellNew]>>%newfile%
echo "FileName"="start.bat">>%newfile%


:BAT FILE
:Create the batch file to be used as a template.
set start=C:\windows\shellnew\start.bat
echo @echo off>%start%
echo :Coder: CutTheRedWire>>%start%
echo :Date: //>>%start%
echo :About: App discription>>%start%


:USE REG FILE
:Runs the reg file to merge it
:Note that if it doesn't wait,
:the reg file is deleted before merging
start /w %newfile%


:CLEAR SYSTEM
:deletes the reg file and clears variables
del %newfile%
set newfile=
set start=
 
13 Aug. 2003 - 09:29 Red
I did my best to make it well commented, and easy to read. Let me know if it makes sense. I figure it's an easy way to change such a thing later. I'm quick with batch files though. ^.^

Coding took about 10 minutes, and checking the registry about the same, but I had done research before. I has been tested though, and worked fine under 98. Check your paths and registry before running it. Not my fault if is messes something up. >:)

Let me know what you guys think of the trick and the app. 8)
 
14 Aug. 2003 - 05:07 methodik
red - cool stuff. :)

i really like the idea of template files, going to have to test this out. ( i'm thinking about readme's here... :) )
 
14 Aug. 2003 - 08:25 Red
Only thing you run into is time you want a file to have no cotent. Text files are an example of that. I'm not sure if it's possible for one file type to have two new file things. Only way I can think of is too create a file type expressly for the second entry. Hmmm....
 
15 Aug. 2003 - 03:34 undefined
Very nice, Red. Thanks for researching this! I can confirm that this works on XP, but the registry key is different (ShellNew rests under the .ext key). For example, .bat would be:

[HKEY_CLASSES_ROOT\.bat\ShellNew]
 
15 Aug. 2003 - 07:49 Red
That works under 98 for new files only, but not for new files witha template. Can you confirm if it works with a template file and where "C:\path\shellnew" is in xp? Is it user specific?

I'm only on 98, so I can test this out.

Oh and thx. ^.^ The compliment is appreciated. I was kinda excited about finding this. The new menu was always a pain to me, but now I'm actually stating to like it. Rip out the crap, add something useful, and you got something cool.

I just hace another idea: a thing for a new extentionless file. Then it could be just about anything you want (esp text based).

One last tip (which I did a thread on before): there is not much need for a new url entry. Reason bing that a new shortcut is changed to a .url file if you simple place a url in the command line. Jus thtought I would reiterate that since it relates to the topic.
 
15 Aug. 2003 - 09:26 undefined
It works with templates, and without templates. But the FileName value is required either way, with no data meaning no template.

The 'blank' file could work out if you attempt to mimic .lnk's behavoir. If you delete the "Command" value under HKCR\.lnk\ShellNew, creating a new shortcut makes an extensionless file. I couldn't get a similar .dud filetype to work the same way, mind you...
 
15 Aug. 2003 - 19:20 Red
Cool. Tried that in 98 a while back with no dice. Finally got a hold of a machine with templates (before I obliteraed them), and figured them out by example. >:)

I wonder if it'll be added to the tweaks here. :P
 
12 Dec. 2007 - 14:56 Red
I just used this at work. I'm so glad this site is still around. Thx plastic!
 
17 Mar. 2010 - 14:46 Red
I've linked to this thread twice in commenting on articles about programs that automate controlling the new file menu. I'm going to link to those articles and the programs.

  • First, the app I use I never saw an article on. Everyone just knows about TweakUI.

  • Second, LifeHacker had an article on ShellMenuNew.

  • Third, gHacks had an article on Shell New Handler.
  •  
    Please log-in to post.
    You need to be logged in to post. To log-in, or to register an account go -there.
     
    Options
    Login | Help | Profile | User list | Display last  
     days 


    ../Msgboard/General customization/New Trick - Make new files with starting templateTop

    xhtml 1.1