当前位置:DOS资源站资料中心VBS脚本 → 根据IP扫描进程是否存在的VBS脚本,记录扫描结果

根据IP扫描进程是否存在的VBS脚本,记录扫描结果

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-5-2 1:54:26

Option Explicit
'On Error Resume Next
Dim intStartingAddress,intEndingAddress,strSubnet,strComputer,ProName
Dim objShell,strCommand,objExecObject,strText

intStartingAddress = 1    '设置起始IP
intEndingAddress = 100    '设置结束IP
strSubnet = "192.168.0."  '设置IP段前缀
ProName = "SMENU.exe"     '你要检查的进程名,注意大小写

Dim Wsh,fso,logfile
Set Wsh = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set logfile = fso.OpenTextFile("扫描记录.txt",2,True)
logfile.Writeline time&" 开始扫描"
logfile.WriteBlankLines(1)
Dim i
For i = intStartingAddress to intEndingAddress
    strComputer = strSubnet & i
    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 2 -w 500 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)
    Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
            If Not CheckPro(strComputer,ProName) Then
       Doit(strComputer)
   End If
        End If
    Loop
Next
logfile.WriteBlankLines(1)
logfile.Writeline time&" 扫描结束"
logfile.close
Msgbox "扫描结束",64,"扫描结束"
WScript.quit


Function CheckPro(strComputer,ProName)
Dim objWMIService,colProcesses,objProcess
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process")
CheckPro = False
For Each objProcess in colProcesses
    If objProcess.Name = ProName Then
 CheckPro = True
 Exit For
    End If
Next
End Function

Sub Doit(strComputer)
logfile.Writeline "注意 "&strComputer&" 状态异常     "&time
Wsh.popup "注意 "&strComputer&" 状态异常",5
End Sub