Option Explicit '------------------------------------------------------------------------- ' VBSTail ' ' Beschreibung ' Liest Testdatei bis zum ende und immer weiter ' '------------------------------------------------------------------------- dim FileTail, intline set FileTail = new clsTail FileTail.input = "c:\test.txt" '~ FileTail.input = "-" ' use STDIn FileTail.storeposition = "HKCU\Software\MSXFAQ\TAIL\meinedatei" FileTail.gotoLastPos '~ FileTail.gototail intline = 0 do while true intline = intline +1 wscript.echo intline &":"& Filetail.getline loop wscript.echo "Skript beendet" class clsTail '~ Helperclass to Read text file or STDIN until end of file reached '~ Waits für new characters to be appended and returns then '~ Version 1.0 '~ uses 100MSec Idle until rechecking the tail of the file. '~ Attn: If you change the source file not at the tail or make it shorter, it will only detect changes after the last file position private inputfs, inputfile private blnStdIn, lngFileSize, strStorePos, lngCurrentPos private objShell private Sub Class_Initialize strStorePos = "" lngCurrentPos = 0 Set objShell = WScript.CreateObject("Wscript.Shell") ' für Eventlog und Registry End Sub public property let input(wert) Set inputfs = CreateObject("Scripting.FileSystemObject") if wert = "-" then Set inputfile = wscript.stdin ' read StandardIn blnStdIn = true else lngFileSize = inputfs.GetFile(wert).size Set inputfile = inputfs.OpenTextFile(wert, 1, false) 'for readin blnStdIn = false end if end property public property let storeposition(wert) strStorePos = wert end property sub gotolastPos dim lngLastPos on error resume next If isnumeric(objShell.RegRead(strStorePos)) Then lngLastPos = objShell.RegRead(strStorePos) inputfile.skip(lngLastPos) lngCurrentPos = lngLastPos end if on error goto 0 end sub sub gototail '~ dim dummy inputfile.skip(lngFileSize) lngCurrentPos = lngFileSize '~ dummy = inputfile.readall end sub function getline '~ Attn: dim strlogline dim blnGotLine if blnStdIn then getline = inputfile.readline else strlogline = "" blnGotLine = false do while not blnGotLine do while (not inputfile.AtEndOfStream) and (not blnGotLine) strlogline = strlogline + inputfile.readline if inputfile.column = 1 then getline = strLogLine lngCurrentPos = lngCurrentPos + len(strLogLine)+2 ' (assume vbcrlf) blnGotLine = true else '~ wscript.echo "Wait für End of Line" end if loop wscript.sleep(100) ' Delay für 100 milisec loop end if if strStorePos <> "" then objShell.RegWrite strStorePos,lngCurrentPos,"REG_DWORD" end if end function end class