‘該程序用來配合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