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-08-05 05:21
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] How to detect a process every 30 seconds and run a specified command? View 2,027 Replies 12
Original Poster Posted 2007-06-21 10:34 ·  中国 江西 南昌 电信
新手上路
Credits 18
Posts 8
Joined 2007-06-21 10:04
19-year member
UID 91951
Gender Male
Status Offline
I need to detect the running of a process every 30 seconds. If it doesn't exist, the computer restarts, and this batch processing runs the detection every 30 seconds.
:loop
tasklist|findstr /i "explorer.exe" ||shutdown -s -t 50
ping 127.1 -n 600 >nul 2>nul
goto loop
I saw this written in the previous post, but when I use it, it must be clicked on this batch processing to work. I hope this batch processing can run by itself every 30 seconds.
I have also read many posts written by everyone in this regard, but when I use it, it doesn't seem to work. I'm a layman and don't understand batch processing. I hope everyone can write a complete batch processing for me to learn. Thank you!


─────────────────── Moderation Record ────────────────────
Performed by: lxmxn
Description: Because the title was not modified within 3 days after being prompted to modify the title, 2 points were deducted, and the title was modified by myself.
─────────────────── Moderation Record ────────────────────


[ Last edited by lxmxn on 2007-6-24 at 11:45 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
lxmxn -2 2007-06-24 23:38
Floor 2 Posted 2007-06-21 10:37 ·  中国 河北 石家庄 北京神州长城通信技术发展中心中国长城互联网
初级用户
★★
Credits 152
Posts 75
Joined 2007-02-06 22:09
19-year member
UID 78805
Gender Male
Status Offline
Oh, this program isn't very good.
@echo off
tasklist >> tasklisttmp.txt
findstr /i "the process name you want to monitor" tasklisttmp.txt >nul
if errorlevel 1 (del tasklisttmp.txt&shutdown -r -f) else del tasklisttmp.txt
ping -n 30 127.0.0.1 > nul
call %0

Didn't test shutdown -r... Changed to del tasklisttmp.txt&echo yes!!! Test succeeded.....
Looking forward to experts' guidance~

[ Last edited by zasxcdfv on 2007-6-21 at 10:48 AM ]
Floor 3 Posted 2007-06-22 14:14 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
Why not put it in the startup at boot? Also, change 600 to 30!!
Floor 4 Posted 2007-06-22 17:34 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
try this one :)

@echo off
rem Should use -r to restart
tasklist|findstr /i "explorer.exe" ||shutdown -r -t 50
rem Moderator willsort said that the first message does not need to wait, so delay for 30 seconds, should use -n 31
ping 127.1 -n 31 >nul 2>nul
rem No need to use a loop, just call itself
call %0
Floor 5 Posted 2007-06-22 23:42 ·  中国 广东 广州 番禺区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
VBS is almost okay..
Batch processing will kill people.
知,不觉多。不知,乃求知
Floor 6 Posted 2007-06-24 21:28 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by flyinspace at 2007-6-22 11:42 PM:
It's better to write with VBS.
Batch processing will drive people crazy.


Can a VBS be written to achieve this function (As long as the computer starts up each time, it automatically calls and runs a certain P process every 30 seconds)


Experts, can it be achieved, please come up with a move啊

[ Last edited by joshualaw on 2007-6-24 at 09:37 PM ]
Floor 7 Posted 2007-06-25 11:11 ·  中国 河北 石家庄 北京神州长城通信技术发展中心中国长城互联网
初级用户
★★
Credits 152
Posts 75
Joined 2007-02-06 22:09
19-year member
UID 78805
Gender Male
Status Offline
Originally posted by HAT at 2007-6-22 05:34 PM:
tasklist|findstr /i "explorer.exe" ||shutdown -r -t 50
rem Bamboo Master willsort said that the first message does not need to wait, so the delay is 30 seconds, it should be -n 31

Got it!

There seemed to be a post before about starting a program automatically by defining it as a service.
LZ can flip through it

[ Last edited by zasxcdfv on 2007-6-25 at 11:14 AM ]
Floor 8 Posted 2007-06-26 21:31 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by zasxcdfv at 2007-6-25 11:11 AM:

Got it!

There seemed to be a previous post about starting a program automatically by defining it as a service.
LZ can look it up.

[ Last edited by zasxcdfv on 2007-6-25 at 11:14 AM ]

Can you link that post here?
Floor 9 Posted 2007-06-26 22:03 ·  中国 广东 深圳 电信
初级用户
Credits 52
Posts 24
Joined 2007-05-09 14:26
19-year member
UID 87949
Gender Male
Status Offline
It can be solved with delay... But if you want to run it after waiting 30 seconds, you need to wait for an expert to handle it..

Delay method



:loop
tasklist|findstr /i "explorer.exe" ||shutdown -s -t 50
setlocal enableextensions
echo WScript.Sleep 30000> %temp%.\tmp$$$.vbs ;Here 30000 is milliseconds. 1000 milliseconds = 1 second. Calculate how long you want to delay by yourself.
@cscript //nologo %temp%.\tmp$$$.vbs
goto loop



This is simple. Just a VB delay is OK

Here's another one to generate a file automatically



echo q | debug>nul
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>sleep.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>sleep.com
echo T}{z~~@GwkBG@OEKcUt`~}@MqqBsy?seHB~_Phxr?@zAB`LrPEyoDt@Cj?>>sleep.com
echo pky_jN@QEKpEt@ij?jySjN@REKpEt@jj?jyGjN@SEKkjtlGuNw?p@pjirz>>sleep.com
echo LFvAURQ?OYLTQ@@?~QCoOL~RDU@?aU?@{QOq?@}IKuNWpe~FpeQFwH?Vkk>>sleep.com
echo _GSqoCvH{OjeOSeIQRmA@KnEFB?p??mcjNne~B?M??QhetLBgBPHexh@e=>>sleep.com
echo EsOgwTLbLK?sFU`?LDOD@@K@xO?SUudA?_FKJ@N?KD@?UA??O}HCQOQ??R>>sleep.com
echo _OQOL?CLA?CEU?_FU?UAQ?UBD?LOC?ORO?UOL?UOD?OOI?UgL?LOR@YUO?>>sleep.com
echo dsmSQswDOR













Floor 10 Posted 2007-06-27 23:47 ·  中国 广东 广州 番禺区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Originally posted by lasting at 2007-6-26 10:03 PM:
Delay can be used to solve it. But if you want to run it after 30 seconds, you need to wait for experts to handle it..

Delay method




This is simple. A VB delay will do.

Then another one to automatically generate a file



I tried it, but it still doesn't seem to work. Does the above P processing can automatically run a certain P processing every 30 seconds (assuming C:\123.bat), similar to "Task Manager", without having to double click.
Floor 11 Posted 2007-06-28 10:17 ·  中国 广东 深圳 电信
初级用户
Credits 52
Posts 24
Joined 2007-05-09 14:26
19-year member
UID 87949
Gender Male
Status Offline
Oh, come on. You want to run it automatically after 30 seconds. Add a scheduled task.
Floor 12 Posted 2007-06-28 11:09 ·  中国 湖南 衡阳 电信
中级用户
★★
Credits 322
Posts 144
Joined 2007-01-10 13:00
19-year member
UID 76062
Gender Male
Status Offline
How to add it in the task scheduler?? There is no such task, right
Floor 13 Posted 2007-06-28 15:31 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Want to use an automatic way, don't want to use task scheduler, can it be done?
Forum Jump: