China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-23 10:02
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Semi-original] How to add a new Bat file in the right-click new View 6,314 Replies 29
Original Poster Posted 2006-10-06 22:57 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
I have been learning DOS independently all the time. Accidentally discovered this forum. When I came in, I was so excited that I almost burst into tears: there are still so many like-minded friends...
Just came here and learned a lot of useful things. Hope to learn more from you all in the future.
Today is Mid-Autumn Festival. Wish you all a happy Mid-Autumn Festival.

I often write BAT files. I always create a new text before and save it as.bat. There is always this cumbersome step. So I want to add the new batch file in the right-click new menu.
Searched and found no such article in the forum. Combined with the article of creating CMD I saw yesterday, borrowed the batch of IceCrack in the post "How to add new batch TEST.CMD file in the right-click new menu", (url)http://www.cn-dos.net/forum/viewthread.php?tid=21417&fpage=1&highlight=%E6%96%B0%E5%BB%BA)
Did a little expansion by myself, modified to add "TestBat" batch file in the right-click new.
Here, the name when creating is defaulted to "New MS-DOS batch file" customized to "New TestBat". Unfortunately, I don't know how to remove the word "New".
Hope this can be regarded as a Mid-Autumn gift for you all:

@echo off
cd /d %temp%
echo Windows Registry Editor Version 5.00 >>tmp.reg
echo.>>tmp.reg
:: The following key is used to add "BAT file" in the right-click new
echo >>tmp.reg
echo "NullFile"="" >>tmp.reg
echo @="" >>tmp.reg
echo.>>tmp.reg
:: The following key is used to customize the name of the new bat file, set to "TestBat" here
echo >>tmp.reg
echo @="TestBat" >>tmp.reg
echo "EditFlags"=hex:30,04,00,00 >>tmp.reg
regedit /s tmp.reg
del tmp.reg
exit

Special thanks to IceCrack, his batch is very good, so I don't want to write it myself, forgive me.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +5 2006-11-19 23:41
Floor 2 Posted 2006-10-06 23:02 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
Just now I thought of it, so I'll let you all know. Change "TestBat" in "echo @="TestBat" >>tmp.reg" to the variable %date%, and you can also create a batch file named with the current time.
Floor 3 Posted 2006-10-06 23:54 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

Thank you for your Mid-Autumn Festival gift~
It's really a case of better late than never. I used to create BAT files as you said before, which was so troublesome~
Today it's finally solved~
At the same time, I wish you and all the friends in the forum a happy Mid-Autumn Festival~~
Floor 4 Posted 2006-10-07 01:04 ·  中国 湖南 株洲 电信
初级用户
★★
Credits 135
Posts 54
Joined 2006-09-10 03:07
19-year member
UID 62265
Status Offline
Thanks
Very good indeed
Floor 5 Posted 2006-10-07 03:41 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
Thanks, I'll take it.
%date:~0,-4% I use this to remove the day of the week.
But I feel that "New" is quite annoying. I wonder if I can remove it and not have it appear in the file name
Floor 6 Posted 2006-10-07 10:54 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
To wydos:
%date:~0,-4% is equivalent to %date:~0,10%
I just saw the usage of ~0,4 in the forum yesterday, and today I learned that -4 means removing the last four digits. Thanks a lot.

The word "New" is really annoying. I will remember this problem and look for a solution. I hope experts can give guidance.
Floor 7 Posted 2006-10-09 13:48 ·  中国 广西 柳州 电信
初级用户
Credits 44
Posts 18
Joined 2006-10-09 09:30
19-year member
UID 65057
Status Offline
Like this function
No need to create a new notepad in the future

The "New" seems to be here... (xp sp2)
The string in the shell32.dll file in the system32 directory, the number of the 260th one is 4156 - (4156, "New")

You can use the software exescope or something else to modify shell32.dll, then replace the original in safe mode (you don't need to go to safe mode first, go to x:\WINDOWS\system32\dllcache to rename shell32.dll, then rename the shell32.dll in use in x:\WINDOWS\system32 for backup, then copy your modified dll to system32, restart, if there are no accidents, it should be okay)

ps: I haven't modified "New" before, I don't know if it's here, but I modified others, it seems okay
Floor 8 Posted 2006-10-09 22:15 ·  中国 北京 中移铁通
初级用户
Credits 28
Posts 14
Joined 2006-08-16 14:31
19-year member
UID 60645
Status Offline
Floor 9 Posted 2006-10-10 09:30 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
TO wydos:
If I want to remove the date.???
How to do it...
Floor 10 Posted 2006-10-10 10:33 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
To h2o:
Thank you for your help. Unfortunately, I can't test it for now. I'll do it later. There are some other things going on these days. I come here just to take a break from being busy, hehe...

To zouzhxi:
It depends on what kind of name you want. If you just want the newly created bat file to be named "New TestBat", just use the code in the post.
Using the current date (including the day of the week):
To remove the day of the week and keep the date, replace the original TestBat code with wydos's code.
To remove the date and keep the day of the week, replace TestBat in the original post with %date:~-3,3% or %date:~11,3%.
Floor 11 Posted 2006-10-10 10:35 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
In fact, the code given in the original post shows the method of customizing the name. The defined name can use string variables or string constants. What kind of display can be returned with echo, and generally, the corresponding name can be used.
Floor 12 Posted 2006-10-10 10:55 ·  中国 贵州 贵阳 电信
中级用户
★★
Credits 304
Posts 117
Joined 2006-04-04 18:43
20-year member
UID 53325
Gender Male
Status Offline
After using it for a few days, the %date% didn't update automatically. It's better not to use this file name. I wonder if you all can automatically update the date - named one?
Floor 13 Posted 2006-10-10 22:35 ·  中国 广西 南宁 西乡塘区 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
%date% is only effective when the bat is run for registration each time (that is, only effective in the bat). %date% directly generates the current day's date in the registry and cannot be modified automatically unless this bat is run automatically every day when the computer starts
Floor 14 Posted 2006-10-11 00:00 ·  中国 黑龙江 哈尔滨 联通
初级用户
Credits 41
Posts 16
Joined 2006-10-01 23:45
19-year member
UID 64267
Status Offline
That is to say, whether it is a variable or a constant, it should be stored in the registry and stored as a constant.

This has not been tried yet. I don't like using dates because they are too long and don't reflect the theme of the bat, which is not user-friendly.

So it is better to use TestBat, write and test this Bat, and then change it to a more practical name.
Floor 15 Posted 2006-10-11 06:29 ·  中国 安徽 安庆 电信
初级用户
Credits 36
Posts 14
Joined 2006-04-29 14:56
20-year member
UID 54667
Status Offline
Wow, such a powerful thing deserves a thumbs-up.
Forum Jump: