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-04 06:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to use a batch file to detect a process View 1,263 Replies 11
Original Poster Posted 2007-04-20 13:40 ·  中国 广东 东莞 电信
初级用户
Credits 60
Posts 23
Joined 2007-02-12 12:58
19-year member
UID 79310
Gender Male
Status Offline
How to use a batch file to determine whether a process exists, and run another batch file
Floor 2 Posted 2007-04-20 20:34 ·  中国 浙江 杭州 电信
银牌会员
★★★
Credits 2,000
Posts 621
Joined 2007-01-01 00:00
19-year member
UID 75212
Gender Male
Status Offline
wmic process get name | find "the process to check" && the batch file to run
Floor 3 Posted 2007-04-20 22:29 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
@echo off
taskklist | find /i "QQ" && echo ok || echo NO
pause

But this "tasklist" isn't as convenient to use as "WMIC". ^O^
欢迎你到批处理爱好者联盟QQ群:18023953
Floor 4 Posted 2007-04-21 02:47 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
wmic can check the exact path
Floor 5 Posted 2007-04-21 03:50 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
How do you use wmic?? Is there any tutorial?
知,不觉多。不知,乃求知
Floor 6 Posted 2007-04-21 04:15 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
There is a complete one on Microsoft's website. I found it once before, but I didn't pay much attention to it, hehe, it seems to be in BIG5.
Floor 7 Posted 2007-04-21 04:16 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
BIG5 is fine too... I can read that as well..

I'll go search for it in a bit.
知,不觉多。不知,乃求知
Floor 8 Posted 2007-04-21 04:19 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Actually the built-in help is quite rich. The main thing is some common keywords and this kind of operating mode.
My usual way of learning is to start from examples and then finish it myself. Most of what I look up online is either commands or English that I can't understand, so you should still do more practical applications.
Floor 9 Posted 2007-04-21 04:23 ·  中国 广东 广州 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
Hehe, my batch file skills were built up by practicing with writing scripts :)

I've already written a large script..<junk file cleanup work> :)

I caught countless bugs in the middle.. discovered countless problems..

In the end I solved them one by one. As a result, I found that my batch file skills had suddenly gone up a level just like that.
知,不觉多。不知,乃求知
Floor 10 Posted 2007-04-21 04:28 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Heh
Floor 11 Posted 2007-04-21 11:31 ·  中国 江西 南昌 电信
初级用户
Credits 57
Posts 28
Joined 2007-04-21 02:13
19-year member
UID 85907
Gender Male
Status Offline
Floor 12 Posted 2007-04-21 12:11 ·  中国 北京 宽捷网通信技术有限公司
初级用户
Credits 84
Posts 28
Joined 2006-05-03 22:36
20-year member
UID 54894
Gender Male
Status Offline
I just learned to write a little simple VBS, so here's my clumsy attempt

Option Explicit
Dim strComputer,wmiNS,wmiQuery,objWMIService
Dim colItems,objItem

wmiNS = "\root\cimv2"
wmiQuery = "Select * from Win32_Process"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & WmiNS)
Set colItems = objWMIService.EXECQuery(WMiQuery)

For Each objItem In colItems
WScript.Echo objItem.Name & vbtab & objItem.executablepath
Next
Forum Jump: