花了我半天时间,终于有负有心人,让我找到了一个基本能实现我的要求的脚本。
但实际使用上有些出入,因为必需用这个监控脚本来启动我自己的脚本。
看能不能改成直接监控的,如果哪位坛友有更好的方法也请贴出来让大家参考一下。
还有一个问题:
dim AppPath
for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_ '列出系统中所有正在运行的程序
if lcase(ps.name)=AppName then'检测程序在进程中是否存在
AppPath=ps.commandline'提取程序的命令行
AppPath1=Replace(AppPath,chr(34),space(1))'用空格替换掉字符串中的双引号这个是我自己加上去的,目的是为了把取得的路径中的双引号进行替换以便跟"allApp"比较,但我实际使用中却无法得到我想要的结果,就是因为这里把双引号替换成空格了,不知有什么方法可以把得到的路径中的双引号去掉而不是替换成空格?
end if
next
'该程序用来配合SimCode调用其他程序,并对程序的运行情况做监控,!
'监控方法是:对系统进程的监控
Set WshShell = Wscript.CreateObject("Wscript.Shell")
allApp="c:\windows\svchost.exe C:\111.vbs" '写下要调用的程序的完整路径。
AppName="svchost.exe" '写下调用的程序的名称.
WshShell.Run (allApp) '启动调用的程序
dim AppPath
for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_ '列出系统中所有正在运行的程序
if lcase(ps.name)=AppName then'检测程序在进程中是否存在
AppPath=ps.commandline'提取程序的命令行
AppPath1=Replace(AppPath,chr(34),space(1))'用空格替换掉字符串中的双引号
end if
next
do'循环检测
myqqin=chkuin(App)'检测上面得到命令行是否在进程中存在!
if not myqqin then'如果没有运行则,告诉用户,并且结束监控!
msgbox "调用的程序已经退出了!"'实际使用中,请取掉这一行!
Exit do
else
wscript.sleep 3000'等待5秒
end if
loop'返回继续检测
function chkuin(App)
for each ps in getobject("winmgmts:\\.\root\cimv2:win32_process").instances_
if lcase(ps.name)=AppName then
AppPatht1=ps.commandline
if AppPatht1=AppPath then chkuin=true end if
end if
next
end function
Last edited by voiL on 2009-8-6 at 22:16 ]