中国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-08-02 14:19
48,038 topics / 350,123 posts / today 1 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » How to open the document every 5 seconds and automatically close the document after 2 seconds
Printable Version  1,593 / 5
Floor1 bbq123bbq Posted 2006-11-17 05:01
初级用户 Posts 77 Credits 197
@echo off
set n=1
:start
cls
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do echo %n% times %%i %%j >>temp.txt
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do echo %n% times %%i %%j
set /a n=%n%+1
rem Remove the limit of showing 20 times, and open temp.txt every 5 seconds
for /l %%a in (0,1,9999) do (
start temp.txt
ping -n 2 127.1 >nul
timeout /t 5 /nobreak >nul
taskkill /f /im notepad.exe >nul 2>nul
)
goto start

The part where it shows the number of times in temp.txt is controlled by itself.. It can only show 20 times. Can it not limit the number of times to open temp.txt, and loop to open temp.txt every 5 seconds? Also, open temp.txt every 5 seconds and automatically close the opened temp.txt after 2 seconds?
Floor2 hxuan999 Posted 2006-11-23 03:13
中级用户 Posts 161 Credits 337
Floor3 vkill Posted 2006-11-23 23:38
金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽
Open temp.txt every 5 seconds, display it for 2 seconds and then automatically close the opened temp.txt

start and taskkill
Floor4 redtek Posted 2006-11-24 02:47
金牌会员 Posts 1,147 Credits 2,902
sendMsg.cmd code is as follows:




In the ":Redtek 2006" label code segment, you can change the initial variables according to your own needs.


Principle: Use the MSG message sending system built into the Windows system to complete the message display tool.
    The /w parameter of MSG has the function of "blocking execution state" to execute and display the current window. When executing, the system is in a waiting state and exits after completion.

    The /TIME parameter of MSG has a time delay function for waiting for the receiver to confirm the message, that is, unless the user actively ends the window, the message will end after the specified n seconds.
    In this way, the method of forcibly killing the process to try to close the message display window is replaced.

    At the same time, MSG can send the specified message to any computer in the local area network, whether it is broadcasting or specifying the receiver, it can be achieved.

    If you use the Ping -n ....<nul command to indirectly achieve the effect of "delay", the CPU will be in a high load state, even up to 90%.
    So CHOICE is used to achieve the effect of waiting for delay. After testing, its CPU peak is about 0-2%.
    And the function of CHOICE to get the user's selected value can achieve terminating the code operation by pressing the specified key, which is convenient for the user to exit safely during execution.

    When executing ARP, its CPU test peak is about 2-13%, which has little impact on the system.


    The statement for /f "delims==" %%i in ('set .') do set "%%i=" is set to clear the used variables.
    The variables used in the code all start with a ".", so when I finish using them, just one For is enough, no need to list them one by one and then delete them.
    This is using SET . When this operation is performed, the system will display all variables starting with ".", and a for will naturally find and "introduce" them all, and then assign an "empty" value to clear the operation.



) Another: If you can't find the CHOICE.EXE file in the Chinese version of Windows XP system, this file is compressed into the attachment of this post together with this code. Friends who need it can download it conveniently : )

Attachments
sendMsg.rar (17.47 KiB)
Floor5 lxmxn Posted 2006-11-25 10:13
版主 Posts 4,938 Credits 11,386
```
@echo off
set/a n=1
:start
cls
for /f "tokens=1,2" %%i in ('arp -a^|findstr /c:" 192.168.0.251"') do (
echo %n% 次 %%i %%j >>temp.txt
echo %n% 次 %%i %%j
)
set/a n+=1
set n_=
set/a n_=%n%%%5
if %n_% equ 0 (
start "" temp.txt >NUL 2>NUL
ping -n 3 127.1 >nul 2>NUL
taskkill /fi "WINDOWTITLE EQ temp.txt - 记事本" >nul 2>nul
REM Because the content in temp.txt is too much, and the temp.txt file is only opened for two seconds and then closed, so it is recommended to clear the content inside first.
REM The next step is to clear, if not needed, you can add REM in front.
cd.>temp.txt)
ping -n 2 127.1>nul
goto start
```
Floor6 lxmxn Posted 2006-11-26 20:34
版主 Posts 4,938 Credits 11,386

Thanks a lot for Brother Redtek's encouragement many times~
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023