|
Option E XPlicit On Error Resume Next Dim intStartingAddress,intEndingAddress,strSubnet,strComputer,ProName Dim objShell,strCommand,objExecObject,strText
intStartingAddress = 247 '设置起始IP intEndingAddress = 251 '设置结束IP strSubnet = "192.168.1." '设置IP段前缀 ProName = "clsmn.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
|