Edituj konstanty měnitelné uživatelem, ale pozor, některé věci jsou hardcoded do kódu, běží to defaultně z c:\temp
REM -----------------------------
REM KONSTANTY menitelne userem
REM -----------------------------
Const FWrow = "00101"
App = "calc.exe"
appdir = "C:\windows\system32\"
progdir = "C:\temp\"
ipfwdata = progdir & "data.txt"
konst = 0
REM -----------------------------
REM KONSTANTY
REM -----------------------------
Const ForReading = 1
Const ForAppending = 8
Const Overwrite = True
REM -----------------------------
REM Test behu aplikace
REM -----------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & App &"'")
If colProcesses.Count = 0 Then
Wscript.Echo "Program nebezi"
Wscript.Quit
End If
REM -----------------------------
REM Definice objektu
REM -----------------------------
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
REM -----------------------------
REM nacteni stare hodnoty
REM -----------------------------
Set objReadFile = objFSO.OpenTextFile(PROGDIR & "status.txt", 1)
oldtraffic = objReadFile.ReadAll
objReadFile.Close
REM -----------------------------
REM vypis stavu ipfw
REM -----------------------------
WshShell.Run "C:\temp\getdata.bat"
Wscript.sleep 2000
REM -----------------------------
REM vyhledani akt. stavu ipfw
REM -----------------------------
Set objTextFile = objFSO.OpenTextFile(ipfwdata, ForReading)
Do While objTextFile.AtEndOfStream <> True
Record = split(objTextFile.Readline, " ")
If Record(0) = FWrow then traffic = Record(2)
Loop
objTextFile.Close
REM -----------------------------
REM zapis predesleho stavu
REM -----------------------------
Set objTextFile = objFSO.CreateTextFile _
(PROGDIR & "status.txt", True)
objTextFile.WriteLine(traffic)
objTextFile.Close
if CLng(oldtraffic + konst) >= CLng(traffic) then
REM -----------------------------
REM terminace
REM ----------------------------
rem strComputer = "."
rem Set objWMIService = GetObject("winmgmts:" _
rem & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & App &"'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next
REM ---------------------------
REM spusteni znova
REM ---------------------------
WshShell.Run appdir&app
end if
pokračování v další reakci