![]() |
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-08-01 20:06 |
48,037 topics / 350,122 posts / today 2 new / 48,249 members |
| DOS批处理 & 脚本技术(批处理室) » Can you write an automatic batch command that executes after the computer is started a specified number of times? |
| Printable Version 3,630 / 15 |
| Floor1 zwzhb | Posted 2006-05-11 17:43 |
| 新手上路 Posts 5 Credits 14 | |
|
For example, the computer records that after starting 50 times, it will automatically format the hard disk, haha
|
|
| Floor2 electronixtar | Posted 2006-05-11 22:57 |
| 铂金会员 Posts 2,672 Credits 7,493 | |
|
Wow, there are always people asking this kind of question on the union~~
|
|
| Floor3 zwzhb | Posted 2006-05-12 12:59 |
| 新手上路 Posts 5 Credits 14 | |
|
Ah, is there anyone else asking?
|
|
| Floor4 bagpipe | Posted 2006-05-12 14:12 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
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.
|
|
| Floor5 bagpipe | Posted 2006-05-12 15:09 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
@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 |
|
| Floor6 zwzhb | Posted 2006-05-12 15:44 |
| 新手上路 Posts 5 Credits 14 | |
|
Ha, thanks first. I'll input it into the batch processing tomorrow and use it. I'll ask you if there's any problem.
|
|
| Floor7 zwzhb | Posted 2006-05-12 15:47 |
| 新手上路 Posts 5 Credits 14 | |
|
By the way, it should be okay to use this program under DOS 6.22, right?
|
|
| Floor8 bagpipe | Posted 2006-05-12 16:09 |
| 银牌会员 Posts 425 Credits 1,144 From 北京 | |
|
What I said is already very clear, and I also wrote down the test environment. DOS 6.22 is not acceptable............
|
|
| Floor9 JonePeng | Posted 2006-05-12 16:22 |
| 金牌会员 Posts 1,883 Credits 4,562 From 广东广州 | |
|
Hehe, it seems that there are more and more posts about using DOS to cause trouble in the forum now.
|
|
| Floor10 zwzhb | Posted 2006-05-12 16:36 |
| 新手上路 Posts 5 Credits 14 | |
|
Of course, it's to restrict the user. Why cause destruction for no reason!
|
|
| Floor11 3742668 | Posted 2006-05-12 19:23 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
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?
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: |
|
| Floor12 willsort | Posted 2006-05-13 17:16 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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: 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 ] |
|
| Floor13 3742668 | Posted 2006-05-13 19:24 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
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. |
|
| Floor14 tigerpower | Posted 2006-05-13 23:36 |
| 中级用户 Posts 99 Credits 377 | |
|
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 ] |
|
| Floor15 willsort | Posted 2006-05-14 19:44 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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 ] |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |