Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Цитата zavoruev:
Не работает, скрипт перестает работать после первого цикла!!! »
Не верю. В строке с «DateDiff(…)», конечно, есть ошибка с вычислением. Но и только:
читать дальше »
Код: Выделить весь код
Option Explicit

Const lngInterval  = 60 ' seconds
Const lngFrequency = 10 ' every 10 seconds


Dim objDictionary

Dim strAddress

Dim objSWbemServicesEx
Dim objSWbemObjectEx

Dim lngCurrentInterval
Dim i


Set objDictionary = WScript.CreateObject("Scripting.Dictionary")

With objDictionary
	.Add 0,     "Success"
	.Add 11001, "Buffer Too Small"
	.Add 11002, "Destination Net Unreachable"
	.Add 11003, "Destination Host Unreachable"
	.Add 11004, "Destination Protocol Unreachable"
	.Add 11005, "Destination Port Unreachable"
	.Add 11006, "No Resources"
	.Add 11007, "Bad Option"
	.Add 11008, "Hardware Error"
	.Add 11009, "Packet Too Big"
	.Add 11010, "Request Timed Out"
	.Add 11011, "Bad Request"
	.Add 11012, "Bad Route"
	.Add 11013, "TimeToLive Expired Transit"
	.Add 11014, "TimeToLive Expired Reassembly"
	.Add 11015, "Parameter Problem"
	.Add 11016, "Source Quench"
	.Add 11017, "Option Too Big"
	.Add 11018, "Bad Destination"
	.Add 11032, "Negotiating IPSEC"
	.Add 11050, "General Failure"
End With

strAddress = "google.com" ' or IP address

Set objSWbemServicesEx = WScript.CreateObject("WbemScripting.SWbemLocator").ConnectServer(".", "root\cimv2")

lngCurrentInterval = 0
i = 0

Do
	For Each objSWbemObjectEx In objSWbemServicesEx.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" & strAddress & "'")
		With objSWbemObjectEx
			If Not IsNull(.StatusCode) Then
				WScript.Echo Now(), .Address, .StatusCode, "[" & objDictionary.Item(.StatusCode) & "]", .ResponseTime
				
				If .StatusCode = 0 Then
					lngCurrentInterval = 0
				End If
			Else
				WScript.Echo Now(), .Address, "Error!"
			End If
		End With
	Next
	
	If lngCurrentInterval >= lngInterval Then
		objSWbemServicesEx.Security_.Privileges.AddAsString "SeShutdownPrivilege", True
		
		For Each objSWbemObjectEx In objSWbemServicesEx.ExecQuery("SELECT * FROM Win32_OperatingSystem")
			'objSWbemObjectEx.Reboot
		Next
		
		Exit Do
	End If
	
	WScript.Sleep lngFrequency * 1000
	
	lngCurrentInterval = lngCurrentInterval + lngFrequency
	
	If DateDiff("h", Time(), TimeSerial(23, 30, 0)) = 0 Then
		Exit Do
	End If
	
	i = i + 1
	WScript.Echo i
Loop

Set objSWbemServicesEx = Nothing

objDictionary.RemoveAll()
Set objDictionary = Nothing

WScript.Quit 0
Результат
Код: Выделить весь код
24.07.2013 16:52:22 google.com 0 [Success] 79
1
24.07.2013 16:52:32 google.com 0 [Success] 278
2
24.07.2013 16:52:43 google.com 11010 [Request Timed Out] null
3
24.07.2013 16:52:55 google.com 11010 [Request Timed Out] null
4
24.07.2013 16:53:06 google.com 0 [Success] 544
5
24.07.2013 16:53:16 google.com 0 [Success] 73
Это сообщение посчитали полезным следующие участники:

Отправлено: 16:52, 24-07-2013 | #25