m0nstar
Goto Top

Ping Script Problem - vbscript

Frage zu meinem Programm!

Hallo,

habe ein kleines Programm geschrieben, was es mir ermöglichen soll einen Computer alle 2 Sekunden anzupingen, dies in einer TXT zu speichern. Nun zu meinem Problem ich versuche grad, dass wenn der PC offline ist mir eine eMail zusenden zulassen. Das Problem ist nun ich will nicht alle 2 Sekunden eine email sondern nur einmal.

In meinem Programm ist ein Fehler, es kommt immer Objekt erforderlich [string: "ON"]

Vllt. kann ja jemand mal drüber schauen und mir eventuell helfen.

	PingForever strHost, strFile

	Sub PingForever(strHost, outputfile)
		Dim Output, Shell, strCommand, ReturnCode

		Set Output = CreateObject("Scripting.FileSystemObject").OpenTextFile(outputfile, 8, True)  
		Set Shell = CreateObject("wscript.shell")  
		strCommand = "ping -n 1 -w 300 " & strHost  
		SET FLAG0 = "ON"  
		While(True)
			ReturnCode = Shell.Run(strCommand, 0, True)     
			If ReturnCode = 0 Then
				Output.WriteLine Date() & " - " & Time & " | " & strHost & " - ONLINE"  
				SET FLAG0 = "ON"  
			Else
				Output.WriteLine Date() & " - " & Time & " | " & strHost & " - OFFLINE"  
				IF FLAG0 = "ON" THEN  
				   SET FLAG0 = "OFF"  
				   Set objEmail = CreateObject("CDO.Message")  
					objEmail.From = "test@test.com"  
					objEmail.To = "test@test.com"  
					objEmail.Subject = "PC " & strHost & " nicht erreichbar"   
					objEmail.Textbody = strText
					objEmail.Configuration.Fields.Item _
						("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
					objEmail.Configuration.Fields.Item _
						("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _  
							"smtpip"   
					objEmail.Configuration.Fields.Item _
						("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25  
					objEmail.Configuration.Fields.Update
					objEmail.Send
				END IF
				
			End If
			Wscript.Sleep 2000
		Wend
	End Sub

Danke schonmal für die hilfe.

Gruß,
m0nstar

Content-Key: 145034

Url: https://administrator.de/contentid/145034

Printed on: April 16, 2024 at 06:04 o'clock

Member: bastla
bastla Jun 17, 2010 at 08:22:42 (UTC)
Goto Top
Hallo m0nstar!

Da ja "FLAGO" nur eine ganz gewöhnliche String-Variable sein soll, ist für die Wertzuweisung (zB in Zeile 9) kein "SET" erforderlich (das wird, wie auch aus der Fehlermeldung ersichtlich, nur für die Erstellung von Objekten benötigt) ...

Grüße
bastla
Member: m0nstar
m0nstar Jun 17, 2010 at 08:29:35 (UTC)
Goto Top
ach danke bastla face-big-smile jetzt glaub ich läuft es auch...so klein kann der fehler sein^^