maniaq Posted September 24, 2005 Share Posted September 24, 2005 (edited) how to integrate new command:new> .bat document into here Edited September 24, 2005 by maniaq Link to comment Share on other sites More sharing options...
DarkShadows Posted September 24, 2005 Share Posted September 24, 2005 (edited) how to integrate new command:new> .bat document<{POST_SNAPBACK}>This is not for the faint at heart. Editing the registry is involved. I will show you how to do one for .cmd files (which is what you should use in Windows 2000/XP). Create a file Template.cmd. Here's mine below, it has some neat things people might like::Start @Echo Off Setlocal enableextensions CLS Echo.:SetVars Set Beep= Set Bullet=ú:Logic :: Place your command batch script logic between :Logic and :End Call :Tips Pause Goto :EOF:End Endlocal Goto :EOF :: Only place called functions below this comment. Do NOT place an Exit :: command anywhere in this script, if you plan to call it from other :: batch scripts, doing so will exit the parent script as well!:Tips :: Text Border Codes :: :: Copy an paste the special characters below to border enhance your :: onscreen messages. :: :: Top Left Corner Double É :: Horizontal Double Í :: Top Right Corner Double » :: Verticle Double º :: Bottom Left Corner Double È :: Bottom Right Corner Double ¼ :: Beep :: :: NOTE: The beep character doesn't actually take up a character space :: on the screen like the other special characters. Use it only :: at the end of a line of text to ensure proper alignment. :: :: The example below displays double bordered text while beeping twice :: (first beep is with the top border, second is with the bottom border). Echo. ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ» Echo. º Your Text Would Go Here º Echo. ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ Echo. Goto :EOFSave this file in a safe location you can always get to. Most templates go inC:\Documents and Settings\All Users\Templates. However, this might be risky on a machine that kids or non technical people have access to. Having a .cmd file on the New menu presents risks, so I advise sticking it in your own user profile. Now you need to tweak the registry. Create a .reg file like so:Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\.cmd\ShellNew]"FileName"="X:\\Folder\\Subfolder\\TemplateFile.cmd"Where you have corrected the drive, the path, and the template file name to what you are using. But keep the double backslashes between your folders.Import the registry file into your registry. You need to reboot for it to take effect. That is all there is to it. You can only have one template for each file type.This works for any file type, just change .cmd before \ShellNew to the extension of your file. Always make sure the template files will always be reliably located; otherwise, you might cause stability issues. Edited September 24, 2005 by DarkShadows Link to comment Share on other sites More sharing options...
maniaq Posted September 25, 2005 Author Share Posted September 25, 2005 tnx for the information, i'm going to test it Link to comment Share on other sites More sharing options...
maniaq Posted September 25, 2005 Author Share Posted September 25, 2005 hmmm, something is weard here.....ok i have thought another way....why should i write that templates.cmd file any info....i can just put it with no info inside and then write the registry....isn't that the same? Link to comment Share on other sites More sharing options...
MHz Posted September 26, 2005 Share Posted September 26, 2005 (edited) Regtweak:Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\.cmd\ShellNew]"FileName"="Template.cmd"Create Template.cmd and add to $OEM$\$DOCS\Default User\Templates. The template can be empty or preset and can also be added to All Users instead. Alternatively, use a Copy command to insert into your User Profile when it exists.Simple. Edited September 26, 2005 by MHz Link to comment Share on other sites More sharing options...
DarkShadows Posted September 26, 2005 Share Posted September 26, 2005 hmmm, something is weard here.....ok i have thought another way....why should i write that templates.cmd file any info....i can just put it with no info inside and then write the registry....isn't that the same?<{POST_SNAPBACK}>It can be an empty file. But you must specify a file. If you structure your command scripts a certain way or routinely use certain code, you can save yourself a lot of work by adding it to your template. Add all of your tips and tricks into your template, and delete what you don't need from the file created from the template on a case-by-case basis. That is what a Template is actually for, but this is not required. Link to comment Share on other sites More sharing options...
DarkShadows Posted April 30, 2009 Share Posted April 30, 2009 I'm revisiting this old thread, with a new idea for others.As I described earlier in this thread, one very effective utilization of a template is to pre-create a file (of whatever file type) containing contents that you are likely to re-use often. This is what a template is intended for.Take for example, a .cmd script.File Extension: .cmdVista File Type Name: Windows Command Script XP File Type Name: Windows NT Command Script When I create a new .cmd script, I usually want to re-use at least some portion of another .cmd script I coded earlier. And as time goes by, and my various scripting techniques become more air-tight and tested, I will develop many re-usable script portions, or code examples. These are what can be added to a template file for later re-use. You don't need to add a whole script (but you could), just the parts that are heavily re-used, or those that are sometimes re-used and difficult to wrap your head around (hopefully with copious comments).Now earlier, this thread discussed adding a template to the Shell Context Menu - New submenu. However, there is more than one way to skin a cat.Giving every user at the same PC access to the same template file may not always be advisable. What I want in my template and what another user wants in their template could be different. This might even depend on the template used. For example, I don't want my family members to have an item titled: "New -> Windows Command Script.cmd" in the their Windows Explorer context menu. They don't know how to write scripts, and they could get themselves (and the system) into trouble, if I left a .cmd file accessible for them to create and later double-click on. (This is why Microsoft didn't create a template for this file type.) But I certainly want a .cmd template for myself, since I write one about once a week. Well fortunately, Windows can handle this scenario. This .reg file suggested above was:Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\.cmd\ShellNew]"FileName"="Template.cmd"Using this file, the Template.cmd file must reside in the current user's profile, under the Templates subfolder, or one must exist in the All Users/Public profile under the Templates folder. The system must also be rebooted before the template will be available from Shell Context Menu - New Submenu. The .reg file below also produces exactly the same results, because HKEY_CLASSES_ROOT is just a short registry address to HKEY_LOCAL_MACHINE\SOFTWARE\Classes.Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.cmd\ShellNew]"FileName"="Template.cmd"Settings under the HKEY_LOCAL_MACHINE hive affect all users. That is, unless a similar setting exists under the HKEY_CURRENT_USER hive and the software in question is designed to make use of the per-user setting. Well guess what? We can do this with templates. The registry file below also works, however, it will only check the current user's profile under the Templates subfolder.Windows Registry Editor Version 5.00[HKEY_CURRENT_USER\Software\Classes\.cmd][HKEY_CURRENT_USER\Software\Classes\.cmd\ShellNew]"FileName"="Template.cmd"The .reg file above will set the same context menu item, but only for the current user. This means I can have my .cmd script template, but not share the template with members of my family (which could be dangerous in this case). Other users on the same PC will not see template listed under Shell Context Menu - New Submenu. In the case of per-user registry settings, you do not need to reboot the PC, you only need logoff and then logon.NOTE: If you add HKEY_CURRENT_USER registry settings during unattended Windows installation, then all users get them. What I have discussed here is more for after Windows is installed. Both Vista and XP share the same behavior. Link to comment Share on other sites More sharing options...
Yzöwl Posted April 30, 2009 Share Posted April 30, 2009 I've uploaded an example, 'New .cmdfile here'.Hope it helps! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now