中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-29 18:33
47,813 topics / 349,918 posts / today 0 new / 48,278 members
DOS批处理 & 脚本技术(批处理室) » After closing, drag the file to the BAT or VBS icon, and then automatically modify the script content
Printable Version  1,692 / 13
Floor1 evilangell Posted 2008-11-23 10:34
初级用户 Posts 32 Credits 32
How to write this bat or vbs????

There is a text file: bak.txt
The content is as follows:


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:


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 ]
Floor2 evilangell Posted 2008-11-23 12:18
初级用户 Posts 32 Credits 32
Thanks for HAT's reminder, I will correct it next time
Floor3 tireless Posted 2008-11-23 16:00
银牌会员 Posts 1,122 Credits 2,025
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:


If you want to add the content of bak_line_number.txt to Tmp.reg, execute this command:


START /wait regedit /s "%Temp%.\Tmp.reg" This sentence is executed separately, which is too cumbersome to add to the text.
Floor4 evilangell Posted 2008-11-23 22:51
初级用户 Posts 32 Credits 32
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.
Floor5 evilangell Posted 2008-11-23 22:57
初级用户 Posts 32 Credits 32
Because the younger brother doesn't understand advanced BAT applications very well, so I ask Brother tireless to help again
Floor6 evilangell Posted 2008-11-23 23:58
初级用户 Posts 32 Credits 32
Well, thank you very much. It would be best to remove the path
Floor7 tireless Posted 2008-11-24 00:05
银牌会员 Posts 1,122 Credits 2,025

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.
Floor8 tireless Posted 2008-11-24 00:07
银牌会员 Posts 1,122 Credits 2,025
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?
Floor9 evilangell Posted 2008-11-24 00:12
初级用户 Posts 32 Credits 32
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
Floor10 evilangell Posted 2008-11-24 00:14
初级用户 Posts 32 Credits 32
@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"
Floor11 evilangell Posted 2008-11-24 00:29
初级用户 Posts 32 Credits 32
Just want to remove the path of the file
Floor12 evilangell Posted 2008-11-24 00:37
初级用户 Posts 32 Credits 32
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"
Floor13 tireless Posted 2008-11-24 00:42
银牌会员 Posts 1,122 Credits 2,025


[ Last edited by tireless on 2008-11-24 at 00:44 ]
Floor14 evilangell Posted 2008-11-24 00:49
初级用户 Posts 32 Credits 32
After testing, no problems were found. Thank you very much, friend.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023