Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Dim strHost, strPath, strFilename, intRetry, objShell
- strHost = "www.google.com" 'Zu pingender Host
- strPath = "C:\Windows\System32\" 'Pfad zum zu startenden Programm
- strFilename = "notepad.exe" 'Dateiname des zu startenden Programms
- intRetry = 10 'Prüfintervall in Sekunden
- Set objShell = WScript.CreateObject("WScript.Shell")
- While(true)
- If Ping(strHost) = true Then
- If IsRunning(strFilename) = false Then
- WScript.Echo "Internetverbindung vorhanden. Starte Programm."
- objShell.Run(strPath & strFilename)
- End If
- Else
- If IsRunning(strFilename) = true Then
- Wscript.Echo "Keine Internetverbindung. Beende Programm."
- objShell.Run("taskkill /IM " & strFilename)
- End If
- End If
- Wscript.Sleep intRetry*1000
- Wend
- Function Ping(strHost)
- Dim objPing, objStatus
- Ping = false
- Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
- ExecQuery("SELECT * FROM Win32_PingStatus WHERE address = '" & strHost & "'")
- For Each objStatus in objPing
- If objStatus.StatusCode = 0 Then
- Ping = true
- Exit Function
- End If
- Next
- End Function
- Function IsRunning(strProcess)
- Dim objProcess, objService
- IsRunning = false
- Set objService = GetObject("winmgmts:")
- For Each objProcess in objService.InstancesOf("Win32_Process")
- If UCase(objProcess.name) = UCase(strProcess) Then
- IsRunning = true
- Exit Function
- End If
- Next
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement