Monitoring Core Process...

chlf2008發表於2011-04-20

strComputer = "."
Const EVENT_SUCCESS=0
Const EVENT_ERROR=1
Const EVENT_WARNING=2
Const EVENT_INFORMATION=4
Const EVENT_AUDIT_SUCCESS=8
Const EVENT_AUDIT_FAILURE=16

'On Error Resume Next

Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")
Set objShell = CreateObject("Wscript.Shell")

Const ForReading = 1
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("input.txt", ForReading)

i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
loop

For Each objItem in objDictionary
strLine = objDictionary.Item(objItem)
strSplit=Split(strLine)
'pDimCount=2
'pName="notepad.exe"
pName=strSplit(0)
pDimCount=strSplit(1)+0
Set colProcesses = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '"&pName&"'")
If colProcesses.Count < pDimCount Then
If Not objFSO.Fileexists(pName) Then
Set f1= objFSO.Createtextfile(pName, true)
Call EventLogingError(pDimCount,colProcesses.Count,pName)
End If
Else
If objFSO.Fileexists(pName) Then
set f2 = objFSO.getfile(pName)
f2.delete
Call EventLogingSuccess(pDimCount,colProcesses.Count,pName)
End If
End If
Next

Function EventLogingError(pDimCount,pCount,pName)
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_ERROR, _
"There are less than "&pDimCount&" (Only exist "&pCount&" ) instances of "&pName&" running"
End Function


Function EventLogingSuccess(pDimCount,pCount,pName)
Set objShell = CreateObject("Wscript.Shell")
objShell.LogEvent EVENT_SUCCESS, _
"There are "&pCount&"/"&pDimCount&" instances of "&pName&" running"
End Function

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12262773/viewspace-1048921/,如需轉載,請註明出處,否則將追究法律責任。

相關文章