|
zwzhb
新手上路

积分 14
发帖 5
注册 2006-5-11
状态 离线
|
『楼 主』:
能不能写一个启动电脑规定次数后执行的自动批处理命令
使用 LLM 解释/回答一下
比如电脑记录启动五十次后自动就把硬盘格式化了,哈
For example, the computer records that after starting 50 times, it will automatically format the hard disk, haha
|
|
2006-5-11 17:43 |
|
|
electronixtar
铂金会员
      
积分 7493
发帖 2672
注册 2005-9-2
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
奇观~~联盟上总是有人问这类问题~~
Wow, there are always people asking this kind of question on the union~~
|
|
2006-5-11 22:57 |
|
|
zwzhb
新手上路

积分 14
发帖 5
注册 2006-5-11
状态 离线
|
|
2006-5-12 12:59 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
呵呵,其实这个在2000/XP/2003系统上是很容易实现的,不过格式化我倒是没有想过,不过不管是重启还是打开机器规定多少次后执行什么命令是可以的
Hehe, actually this is very easy to achieve on systems like 2000/XP/2003. But I haven't thought about formatting. However, it's possible to set what command to execute after restarting or powering on the machine a specified number of times.
|
|
2006-5-12 14:12 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
@echo off
set i=1
if not exist c:\test.txt goto A
:C
if exist c:\test.txt goto D
:A
echo ^0>test.txt
goto C
:D
for /f %%i in (c:\test.txt) do set /a k=%%i+%i%
if "%k%"=="50" (goto B) else echo %k% 1>c:\test.txt&goto :eof
:B
echo SUCCESSFUL .... ....
这个是你想要执行的程序
粗略的写了一个,好像还能够更加简洁,不过这个不敢保证人家会不会进入系统后运行这个批处理,总之运行一次就少一次,呵呵,把这个放到启动里就可以了
测试环境 WINDOWS XP & WINDOWS 2000
@echo off
set i=1
if not exist c:\test.txt goto A
:C
if exist c:\test.txt goto D
:A
echo ^0>test.txt
goto C
:D
for /f %%i in (c:\test.txt) do set /a k=%%i+%i%
if "%k%"=="50" (goto B) else echo %k% 1>c:\test.txt&goto :eof
:B
echo SUCCESSFUL .... ....
This is the program you want to execute
Roughly written, it seems it can be more concise, but I can't guarantee whether people will run this batch script after entering the system. In short, it runs once and decreases by one. Hehe, just put this in the startup.
Test environment WINDOWS XP & WINDOWS 2000
|
|
2006-5-12 15:09 |
|
|
zwzhb
新手上路

积分 14
发帖 5
注册 2006-5-11
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
哈,先谢谢了,明天就输入到批处理里用用,有问题再请教你
Ha, thanks first. I'll input it into the batch processing tomorrow and use it. I'll ask you if there's any problem.
|
|
2006-5-12 15:44 |
|
|
zwzhb
新手上路

积分 14
发帖 5
注册 2006-5-11
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
对了,在DOS6.22下用这个程序也应该是没问题的吧
By the way, it should be okay to use this program under DOS 6.22, right?
|
|
2006-5-12 15:47 |
|
|
bagpipe
银牌会员
     DOS联盟捡破烂的
积分 1144
发帖 425
注册 2005-10-20 来自 北京
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
我说的已经很清楚了,测试环境我也写上了,DOS 6.22不可以............
What I said is already very clear, and I also wrote down the test environment. DOS 6.22 is not acceptable............
|
|
2006-5-12 16:09 |
|
|
JonePeng
金牌会员
      D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
呵呵,貌似现在论坛里用 DOS 搞破坏的帖子越来越多了。
Hehe, it seems that there are more and more posts about using DOS to cause trouble in the forum now.
|

----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2006-5-12 16:22 |
|
|
zwzhb
新手上路

积分 14
发帖 5
注册 2006-5-11
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
当然是为了限制使用人了,没事搞什么破坏!
Of course, it's to restrict the user. Why cause destruction for no reason!
|
|
2006-5-12 16:36 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
哈哈,用格式化来限制使用的方法够牛,不过只要有兴趣,就从搞破坏开始又有何妨?
@echo off
set /p num=<num.txt || echo 1 > num.txt
if %num% equ 50 goto something
set /a num = %num% + 1
echo %num% > num.txt
echo 这是第 %num% 次运行...
pause
goto :eof
:something
echo 50次到了。。。 & pause
上面这个演示脚本运行在XP SP2下,如果想写个在DOS下运行的也不是没有可能,不过代码量相对大多了,所以略过,可以给点提示:
@echo off
dir *.cxs
if errorlevel 1 echo ^&*HUIT^&%T^&%& > 1.cxs
if exist 50.cxs goto something
ren 48.cxs 49.cxs
ren 47.cxs 48.cxs
.
.
.
.
ren 1.cxs 2.cxs
goto :exit
:something
echo 已运行50次。
:exit
Hehe, the method of using formatting to restrict usage is quite clever, but as long as there's interest, why not start from causing damage?
@echo off
set /p num=<num.txt || echo 1 > num.txt
if %num% equ 50 goto something
set /a num = %num% + 1
echo %num% > num.txt
echo This is the %num%th run...
pause
goto :eof
:something
echo 50 runs are up... & pause
The above demonstration script runs under XP SP2. If you want to write one that runs under DOS, it's not impossible, but the amount of code is relatively larger, so it's skipped. Here are some hints:
@echo off
dir *.cxs
if errorlevel 1 echo ^&*HUIT^&%T^&%& > 1.cxs
if exist 50.cxs goto something
ren 48.cxs 49.cxs
ren 47.cxs 48.cxs
.
.
.
.
ren 1.cxs 2.cxs
goto :exit
:something
echo 50 runs have been made.
:exit
|
|
2006-5-12 19:23 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Re zwzhb:
其实根据启动次数来触发事件的批处理,已经接近于病毒的检测机制了。但实际上它实现起来非常简单,即使在DOS下也存在许多方案。所以,它是我在早期研究批处理伪病毒时最先完成的模块。
只是基于控制危险技术传播速度的目地,我只能提供大略的思路,不能贴出源码,事实上,我过去的源码也很难找到了。根据启动次数判断是否触发事件的前提是测得启动次数,如何获取并检测这个次数,可以有多种算法。
比如bagpipe和3742668兄所涉及的保存启动次数到变量并逐次递增的方案,在DOS下因为实现环境变量的加减比较复杂,所以可以将这种方法略作变形,将启动次数转变为临时文件的行数(可用find检测)或者总字节数(一般是次数*3)进行保存和检测。
或者也可以使用3742668兄第二方案中的压栈法将启动次数保存在文件名中,真正实现时可以不用逐行进行改名压栈,使用简单的命令行循环即可完成此项任务。
Re bagpipe:
感觉你的代码,为了照顾程序的结构上的顺序性,而影响了程序的简洁性和可阅读性。
比如 if not exist c:\test.txt goto A 和 if exist c:\test.txt goto D 便存在着代码冗余。而A、B、C、D四个标签段和相应的goto,也使程序的结构变得复杂。经过仔细考量,我认为这个标签可以全部略去,因为 c:\test.txt 的存在性判定可以由for语句稍加修改来一并完成,而其它跳转和分支也可以简并。
另外,兄使用变量 i 保存递增次数1,应该有特别的考量,恕我难以猜度。
最后,记得兄曾经贴过一张“风笛乐符字母”的签名图片,不知可否赠我一份聊作收藏?如若有意,请直接发往我的邮箱即可,不胜感谢!
Re 3742668:
如果将 set /a 一句直接写入临时批处理中保存,是否更简便些呢?比如:
if exist _bootnum.cmd (call _bootnum.cmd) else set bootnum=1
echo set /a bootnum=%bootnum%+1>_bootnum.cmd
if bootnum equ 50 goto .....
To Wengier:
此主题可以转往“批处理室”继续讨论了,请略为代转。
Last edited by willsort on 2006-5-13 at 17:23 ]
Re zwzhb:
Actually, the batch script that triggers an event based on the number of startups is already close to the detection mechanism of a virus. But in fact, it's very simple to implement, and there are many solutions even under DOS. So, it was the first module I completed when I was researching batch pseudo-viruses in the early days.
Just for the purpose of controlling the spread speed of dangerous technologies, I can only provide a general idea, not the source code. In fact, it's very hard to find my past source code. The premise of judging whether to trigger an event based on the number of startups is to measure the number of startups. There are various algorithms to obtain and detect this number.
For example, the solution of bagpipe and Brother 3742668 involving saving the number of startups to a variable and incrementing it one by one. Under DOS, because it's complicated to add and subtract environment variables, this method can be slightly modified. Convert the number of startups into the number of lines in a temporary file (detectable with find) or the total number of bytes (usually 3 times the number of times) for saving and detection.
Or, you can also use the stack method in Brother 3742668's second solution to save the number of startups in the file name. When actually implementing it, you don't need to rename and stack line by line. A simple command line loop can complete this task.
Re bagpipe:
I feel that your code affects the simplicity and readability of the program because of taking care of the sequentiality in the program structure.
For example, if not exist c:\test.txt goto A and if exist c:\test.txt goto D have code redundancy. And the four label segments A, B, C, D and the corresponding goto also make the program structure complicated. After careful consideration, I think these labels can all be omitted because the existence judgment of c:\test.txt can be completed at the same time by slightly modifying the for statement, and other jumps and branches can also be simplified.
In addition, brother uses the variable i to save the incremented number 1, which should have special considerations, but I can't guess it.
Finally, I remember that brother once posted a signature picture of "bagpipe musical note letters". Can you give me a copy for collection? If you are interested, please send it directly to my email. Thank you very much!
Re 3742668:
Is it more convenient to directly write the set /a sentence into the temporary batch file for saving? For example:
if exist _bootnum.cmd (call _bootnum.cmd) else set bootnum=1
echo set /a bootnum=%bootnum%+1>_bootnum.cmd
if bootnum equ 50 goto .....
To Wengier:
This topic can be transferred to "Batch Processing Room" for further discussion. Please help transfer it a little.
Last edited by willsort on 2006-5-13 at 17:23 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-13 17:16 |
|
|
3742668
荣誉版主
      
积分 2013
发帖 718
注册 2006-2-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Re willsort:
看了兄的回贴,感觉兄的风格还是偏向于DOS,而我的风格无疑是偏向CMD。
相信不少人都会有这样的想法:写批处理的时候尽量不要产生临时文件。尽管这其实并不是什么大的问题,和每次系统启动以及磁盘交换带来来比,可以忽略不计,但是还是有不少朋友喜欢用for来操作输出句柄。而我在写这个WINDOWS下的批处理前,自然就是迎合大众,以不产生临时文件为主。在本例中,不产生临时文件的方法其实有好几种,个人认为最简单,最方便的应该是利用NTFS格式的文件流了。所以一开始我是打算把启动次数写入到文件本身%0的某个非主流中的,但是写到一半想到并非人人都使用NTFS格式分区,为了"兼容",所以还是写到了一个文件中。
当然,如果为了不产生临时文件的话,方法其实还是蛮多的,可以用for,find以及事件日志命令等等。
回这个贴主要是想了解一下:
或者也可以使用3742668兄第二方案中的压栈法将启动次数保存在文件名中,真正实现时可以不用逐行进行改名压栈,使用简单的命令行循环即可完成此项任务。
不知能否给出DOS下命令行循环的思路,由于我这没有DOS环境,所以无法得知具体每个命令在DOS下各有哪些参数,所以对于DOS下的批处理从来只能提提思路,未敢妄自菲薄,闭门造车。麻烦兄能贴出需要的几条命令以及需要用到的参数,至于具体代码不如自己写来得深刻。
Re regarding the sort:
After reading your post, I feel that your style still leans towards DOS, while mine undoubtedly leans towards CMD.
I believe many people will have such an idea: try not to generate temporary files when writing batch scripts. Although this is actually not a big problem and can be ignored compared to each system startup and disk swapping, there are still many friends who like to use for to operate the output handle. And before I wrote this batch script under WINDOWS, I naturally catered to the public, focusing on not generating temporary files. In this example, there are actually several ways to not generate temporary files. Personally, I think the simplest and most convenient one is to use the file streams of the NTFS format. So at the beginning, I planned to write the startup count into a non-mainstream part of %0 of the file itself, but halfway through writing, I thought that not everyone uses NTFS formatted partitions. For "compatibility", I still wrote it into a file.
Of course, if you want to not generate temporary files, there are actually quite a few methods. You can use for, find, and event log commands, etc.
I'm replying to this post mainly to understand:
Or you can also use the stack method in brother 3742668's second solution to save the startup count in the file name. When actually implementing it, you don't need to rename and stack line by line, and you can complete this task using a simple command line loop.
I wonder if you can give the idea of the command line loop under DOS. Since I don't have a DOS environment here, I can't know what parameters each command has under DOS, so I have only been able to mention ideas about batch processing under DOS and haven't dared to be overconfident and make things up. Please post the necessary commands and the parameters needed, and as for the specific code, it's better to write it yourself to be more profound.
|
|
2006-5-13 19:24 |
|
|
tigerpower
中级用户
   大师兄
积分 377
发帖 99
注册 2005-8-26
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
在dos批处理方面偶对willsort板主十分佩服,思考比较缜密,脚本通用性也比较好,还有些技巧偶是闻所未闻,让人大开眼界呀:)
Last edited by tigerpower on 2006-5-13 at 23:38 ]
I really admire the board master willsort in terms of DOS batch processing. The thinking is quite meticulous, the script versatility is also relatively good, and there are some tricks that I have never heard of before, which is really eye-opening : )
Last edited by tigerpower on 2006-5-13 at 23:38 ]
|
|
2006-5-13 23:36 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Re 3742668:
启动次数的判定,无论采用何种算法,都需要设定一个“标记”,而且这个标记不会在关机后丢失,所以留给我们的选择似乎只余磁盘文件一途了。如果不想利用临时文件,系统文件或者批处理自身也许是个“标记”的藏身地,只不过存取起来就比较复杂了。
我所说的“命令行循环”,实际上就是指通过命令行参数将遍历对象传给自身,然后再使用shift+goto的loop循环,我在后期编写DOS下的递增或遍历型循环时,基本上多采用这种这种方式,因为它比for更加灵活。即使是与CMD的FOR相比,它也具有可以某一个时刻引用前后多个遍历对象的优点。在CMD下也可以实现这种方式,而且因为CALL的特性会更加简单一些。
DOS下的范例可以参考:
14512-将100个顺序文件改名
http://www.cn-dos.net/forum/viewthread.php?tid=14512
Last edited by willsort on 2006-5-14 at 20:24 ]
Re 3742668:
The determination of the number of startups, no matter which algorithm is adopted, requires setting a "marker", and this marker will not be lost after shutting down. So the only option left for us seems to be disk files. If we don't want to use temporary files, the system file or the batch file itself may be a place to hide the "marker", but accessing it is relatively complicated.
The "command line loop" I mentioned actually refers to passing the traversal object to itself through command line parameters, and then using the shift+goto loop. When I later wrote incrementing or traversal loops under DOS, I basically mostly used this method because it is more flexible than for. Even compared with CMD's FOR, it has the advantage of being able to refer to multiple traversal objects before and after at a certain moment. This method can also be implemented under CMD, and it will be simpler because of the characteristics of CALL.
For examples under DOS, you can refer to:
14512-Rename 100 sequential files
http://www.cn-dos.net/forum/viewthread.php?tid=14512
Last edited by willsort on 2006-5-14 at 20:24 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2006-5-14 19:44 |
|