‘該程序用來配合SimCode調用其他程序,并對程序的運行情況做監(jiān)控,! ‘監(jiān)控方法是:查找程序的Log文件,如果有結束標志,說明程序已經(jīng)執(zhí)行完畢! 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不成立時,一直循環(huán)! set fso=Wscript.CreateObject(”Scripting.FileSystemObject”) Set ts=fso.opentextfile(”c:\kw.txt”)'打開調用的程序日生的日志文件 Do While Not ts.AtEndOfStream'當沒有到文件尾時循環(huán) data=ucase(trim(ts.readline))'讀取日志文件中的一行 If instr(data,”O(jiān)K”) Then'查找上面讀取到的內(nèi)容是否存在程序運行完的標志!此例中標志為”O(jiān)K” i=1′當?shù)玫匠绦蜻\行完成的標志時,傳遞一個值給Do循環(huán),使其結束循環(huán),不再對Log文件監(jiān)控 Exit Do End If loop Set ts = nothing Set fso = nothing'關閉創(chuàng)建的對象 wscript.sleep 2000′等待2秒后,進行下一輪對Log文件的監(jiān)控 loop wscript.echo “OK!”‘給用戶一個反饋,調用的程序執(zhí)行完畢!真實使用時,應該不要這一行! 第二個:
dim AppPath for each ps in getobject(”winmgmts:\\.\root\cimv2:win32_process”).instances_ ‘列出系統(tǒng)中所有正在運行的程序 if lcase(ps.name)=AppName then'檢測程序在進程中是否存在 AppPath=ps.commandline'提取程序的命令行 end if next
do'循環(huán)檢測 myqqin=chkuin(App)'檢測上面得到命令行是否在進程中存在! if not myqqin then'如果沒有運行則,告訴用戶,并且結束監(jiān)控! msgbox “調用的程序已經(jīng)退出了!”‘實際使用中,請取掉這一行! Exit do else wscript.sleep 3000′等待5秒 end if loop'返回繼續(xù)檢測
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