‘该程序用来配合SimCode调用其他程序,并对程序的运行情况做监控,! ‘监控方法是:查找程序的Log文件,如果有结束标志,说明程序已经执行完毕! Set WshShell=Wscript.CreateObject(”Wscript.Shell”) WshShell.Run(”notepad.exe c:/kw.txt”)'调用的程序 wscript.sleep 2000′等待2秒钟 Dim fso,ts,i Do While Not i=1′当i=1不成立时,一直循环! set fso=Wscript.CreateObject(”Scripting.FileSystemObject”) Set ts=fso.opentextfile(”c:/kw.txt”)'打开调用的程序日生的日志文件 Do While Not ts.AtEndOfStream'当没有到文件尾时循环 data=ucase(trim(ts.readline))'读取日志文件中的一行 If instr(data,”OK”) Then'查找上面读取到的内容是否存在程序运行完的标志!此例中标志为”OK” i=1′当得到程序运行完成的标志时,传递一个值给Do循环,使其结束循环,不再对Log文件监控 Exit Do End If loop Set ts = nothing Set fso = nothing'关闭创建的对象 wscript.sleep 2000′等待2秒后,进行下一轮对Log文件的监控 loop wscript.echo “OK!”‘给用户一个反馈,调用的程序执行完毕!真实使用时,应该不要这一行! 第二个:
dim AppPath for each ps in getobject(”winmgmts://./root/cimv2:win32_process”).instances_ ‘列出系统中所有正在运行的程序 if lcase(ps.name)=AppName then'检测程序在进程中是否存在 AppPath=ps.commandline'提取程序的命令行 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