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-07-07 03:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » After closing, drag the file to the BAT or VBS icon, and then automatically modify the script content View 1,530 Replies 13
Original Poster Posted 2008-11-23 10:34 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
How to write this bat or vbs????

There is a text file: bak.txt
The content is as follows:
>>"%Temp%.\Tmp.reg" ECHO "1"="aaa.exe"
>>"%Temp%.\Tmp.reg" ECHO "2"="bbb.exe"
>>"%Temp%.\Tmp.reg" ECHO "3"="ccc.exe"
>>"%Temp%.\Tmp.reg" ECHO "4"="ddd.exe"
>>"%Temp%.\Tmp.reg" ECHO "5"="eee.exe"
START /wait regedit /s "%Temp%.\Tmp.reg"


Now I want to write such a bak.bat or bak.vbs
There is a program fff.exe,
I directly drag the fff.exe to the bak.bat or bak.vbs icon, and then bak.txt becomes as follows:
>>"%Temp%.\Tmp.reg" ECHO "1"="aaa.exe"
>>"%Temp%.\Tmp.reg" ECHO "2"="bbb.exe"
>>"%Temp%.\Tmp.reg" ECHO "3"="ccc.exe"
>>"%Temp%.\Tmp.reg" ECHO "4"="ddd.exe"
>>"%Temp%.\Tmp.reg" ECHO "5"="eee.exe"
>>"%Temp%.\Tmp.reg" ECHO "6"="fff.exe"
START /wait regedit /s "%Temp%.\Tmp.reg"


Can continue to drag other programs to the bak.bat or bak.vbs icon, and continue to add in an orderly manner

───────────────── Moderation Record ─────────────────
Execution: HAT
Operation: Add search keywords in the post title; add code tags to the code
Explanation: The original title "How to write this bat or vbs????" is not conducive to forum search
Punishment: Deduct 2 points of points
Tip: It is recommended to read the following posts
{1415}The Wisdom of Asking Questions
{7326}Must-read for forum newcomers, basic code of conduct for everyone
{22703}Please don't be an impatient person
{32667} Those who can't even write the title clearly, wake up
{32825}This version is strictly rectifying bad posts
───────────────── Moderation Record ─────────────────


[ Last edited by HAT on 2008-11-24 at 02:03 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT -2 2008-11-23 10:47
Floor 2 Posted 2008-11-23 12:18 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Thanks for HAT's reminder, I will correct it next time
Floor 3 Posted 2008-11-23 16:00 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Suggest changing the method.

Drag and drop any number of files onto the following batch script. Each time you drag and drop a file, it will modify the line number number in the filename of bak_line_number.txt. The "line number" corresponds to the last line number in the text of bak_line_number.txt, so it's convenient to read the line number when dragging and dropping files next time:
@echo off
if "%~1" equ "" echo Please drag and drop any number of files onto this batch script. Press any key to exit...&pause>nul&exit /b

cd /d "%~dp0"
if not exist bak_*.txt type nul>bak_0.txt

for /f "delims=_. tokens=2" %%a in ('dir /a:-d /b bak_*.txt') do (
set n=%%a
set file=bak_%%a.txt
)

for %%a in (%*) do (
set /a n+=1
>>%file% call echo "%%n%%"="%%~a"
)

ren %file% bak_%n%.txt


If you want to add the content of bak_line_number.txt to Tmp.reg, execute this command:
copy "%Temp%.\Tmp.reg"+bak_line_number.txt


START /wait regedit /s "%Temp%.\Tmp.reg" This sentence is executed separately, which is too cumbersome to add to the text.
Floor 4 Posted 2008-11-23 22:51 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Thanks to the friends in LS.

Actually, the original problem is like this:

The original bak.txt was originally a BAT file, which I deliberately changed when I asked the question.

The source file is as follows (named: Restrict Restricted.bat):
@cls&@echo.&@color f3&@cd..\&@cls
> "%Temp%.\Tmp.reg" ECHO Windows Registry Editor Version 5.00
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]
>>"%Temp%.\Tmp.reg" ECHO "1"="regedit.exe"
>>"%Temp%.\Tmp.reg" ECHO "2"="regedt32.exe"
>>"%Temp%.\Tmp.reg" ECHO "3"="cmd.exe"
>>"%Temp%.\Tmp.reg" ECHO "4"="rundll32.exe"
>>"%Temp%.\Tmp.reg" ECHO "5"="smagent.exe"
>>"%Temp%.\Tmp.reg" ECHO "6"="shell32.dll"
>>"%Temp%.\Tmp.reg" ECHO "7"="msconfig.exe"
>>"%Temp%.\Tmp.reg" ECHO "8"="mspaint.exe"
>>"%Temp%.\Tmp.reg" ECHO "9"="shutdown.exe"
>>"%Temp%.\Tmp.reg" ECHO "10"="hh.exe"
>>"%Temp%.\Tmp.reg" ECHO "11"="IEXPLORE.EXE"
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
>>"%Temp%.\Tmp.reg" ECHO "RestrictRun"=dword:00000001
@START /wait regedit /s "%Temp%.\Tmp.reg"
@ping -n 2 127.0.0.1 > nul
@gpupdate.EXE /force > nul
@ping -n 2 127.0.0.1 > nul
@DEL "%Temp%.\Tmp.reg"

If there is a program such as OK.EXE dragged into this Restrict Restricted.bat, or into the BAT file created by tireless, then the content of Restrict Restricted.bat becomes as follows:

@cls&@echo.&@color f3&@cd..\&@cls
> "%Temp%.\Tmp.reg" ECHO Windows Registry Editor Version 5.00
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]
>>"%Temp%.\Tmp.reg" ECHO "1"="regedit.exe"
>>"%Temp%.\Tmp.reg" ECHO "2"="regedt32.exe"
>>"%Temp%.\Tmp.reg" ECHO "3"="cmd.exe"
>>"%Temp%.\Tmp.reg" ECHO "4"="rundll32.exe"
>>"%Temp%.\Tmp.reg" ECHO "5"="smagent.exe"
>>"%Temp%.\Tmp.reg" ECHO "6"="shell32.dll"
>>"%Temp%.\Tmp.reg" ECHO "7"="msconfig.exe"
>>"%Temp%.\Tmp.reg" ECHO "8"="mspaint.exe"
>>"%Temp%.\Tmp.reg" ECHO "9"="shutdown.exe"
>>"%Temp%.\Tmp.reg" ECHO "10"="hh.exe"
>>"%Temp%.\Tmp.reg" ECHO "11"="IEXPLORE.EXE"
>>"%Temp%.\Tmp.reg" ECHO "12"="OK.EXE"
>>"%Temp%.\Tmp.reg" ECHO.
>>"%Temp%.\Tmp.reg" ECHO [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
>>"%Temp%.\Tmp.reg" ECHO "RestrictRun"=dword:00000001
@START /wait regedit /s "%Temp%.\Tmp.reg"
@ping -n 2 127.0.0.1 > nul
@gpupdate.EXE /force > nul
@ping -n 2 127.0.0.1 > nul
@DEL "%Temp%.\Tmp.reg"

Because it is too cumbersome to add manually each time, that's why I had the idea of dragging it in to add automatically.
Floor 5 Posted 2008-11-23 22:57 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Because the younger brother doesn't understand advanced BAT applications very well, so I ask Brother tireless to help again
Floor 6 Posted 2008-11-23 23:58 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Well, thank you very much. It would be best to remove the path
Floor 7 Posted 2008-11-24 00:05 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
@echo off
if "%~1" neq "" goto add
more +23 %0>"%Temp%.\Tmp.reg"
START /wait regedit /s "%Temp%.\Tmp.reg"
ping -n 2 127.0.0.1 > nul
gpupdate.EXE /force > nul
ping -n 2 127.0.0.1 > nul
DEL "%Temp%.\Tmp.reg"
exit /b

:add
cd /d "%~dp0"
for /f "delims==" %%a in ('findstr ^^\".*\" %0^|sort /r') do (
set "n=%%~a" & goto next
)

:next
for %%a in (%*) do (
set /a n+=1
>>%0 call echo "%%n%%"="%%~a"
)
exit /b

Windows Registry Editor Version 5.00




Notes:

① The last line should be a blank line.

② If you need to add or delete code lines before Windows Registry Editor Version 5.00, you need to modify the red number in this sentence:

more +23 %0>"%Temp%.\Tmp.reg"

This number is the number of lines before Windows Registry Editor Version 5.00.
Floor 8 Posted 2008-11-24 00:07 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
Originally posted by evilangell at 2008-11-23 11:58 PM:
Well, thank you very much. It would be best to remove the path

Which path?
Floor 9 Posted 2008-11-24 00:12 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Thanks friend

After testing, the following problems are found:

1. I want to remove the path

2. Can only add to 19, and when continuing to add, it becomes starting from the 10th again
Floor 10 Posted 2008-11-24 00:14 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
@echo off
if "%~1" neq "" goto add
more +23 %0>"%Temp%.\Tmp.reg"
START /wait regedit /s "%Temp%.\Tmp.reg"
ping -n 2 127.0.0.1 > nul
gpupdate.EXE /force > nul
ping -n 2 127.0.0.1 > nul
DEL "%Temp%.\Tmp.reg"
exit /b

:add
cd /d "%~dp0"
for /f "delims==" %%a in ('findstr ^^\"[0-9].*\" %0^|sort /r') do (
set "n=%%~a" & goto next
)

:next
for %%a in (%*) do (
set /a n+=1
>>%0 call echo "%%n%%"="%%~a"
)
exit /b

Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\RestrictRun]
"1"="regedit.exe"
"2"="C:\\Documents and Settings\\Administrator\\桌面\\Restrict+BAT\\AnyDel.bat"
"3"="C:\\Documents and Settings\\Administrator\\桌面\\Restrict+BAT\\IP自动设置.lnk"
"4"="C:\\Documents and Settings\\Administrator\\桌面\\Restrict+BAT\\NTFS文件锁定程序.bat"
Floor 11 Posted 2008-11-24 00:29 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Just want to remove the path of the file
Floor 12 Posted 2008-11-24 00:37 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
After multiple tests, it may not necessarily be 19. Sometimes two identical ones appear as follows:

"8"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Anti-piracy Black Screen.bat"
"9"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Manual Migration of Personal Data.bat"
"10"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\File (S).bat"
"11"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\regedit.exe"
"12"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Restrict Restricted.jpg"
"10"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\AnyDel.bat"
"11"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\IP Automatic Setup.lnk"
"12"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\NTFS File Locking Program.bat"
"13"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Restrict Effective.bat"
"14"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Restrict Effective.exe"
"15"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Restrict Restricted (Security Edition).bat"
"16"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\UnRestrict.bat"
"17"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Anti-piracy Black Screen.bat"
"18"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Manual Migration of Personal Data.bat"
"19"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\File (S).bat"
"20"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\regedit.exe"
"21"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\Restrict Restricted.jpg"
"10"="C:\Documents and Settings\Administrator\Desktop\Restrict+BAT\AnyDel.bat"
Floor 13 Posted 2008-11-24 00:42 ·  中国 江西 赣州 安远县 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
@echo off
if "%~1" neq "" goto add
more +20 %0>"%Temp%.\Tmp.reg"
START /wait regedit /s "%Temp%.\Tmp.reg"
ping -n 2 127.0.0.1 > nul
gpupdate.EXE /force > nul
ping -n 2 127.0.0.1 > nul
DEL "%Temp%.\Tmp.reg"
exit /b

:add
cd /d "%~dp0"
for /f %%a in ('find /v /c "" %0') do set "n=%%~a-2"
for /f "delims==" %%a in ('more +%n% %0') do set n=%%~a
for %%a in (%*) do (
set /a n+=1
>>%0 call echo."%%n%%"="%%~nxa"
)
exit /b

Windows Registry Editor Version 5.00





[ Last edited by tireless on 2008-11-24 at 00:44 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT +2 2008-11-24 02:03
Floor 14 Posted 2008-11-24 00:49 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
After testing, no problems were found. Thank you very much, friend.
Forum Jump: