Advertisement
Guest User

Untitled

a guest
Aug 7th, 2016
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Dim strHost, strPath, strFilename, intRetry, objShell
  4.  
  5. strHost = "www.google.com"              'Zu pingender Host
  6. strPath = "C:\Windows\System32\"        'Pfad zum zu startenden Programm
  7. strFilename = "notepad.exe"             'Dateiname des zu startenden Programms
  8. intRetry = 10                           'Prüfintervall in Sekunden
  9.  
  10. Set objShell = WScript.CreateObject("WScript.Shell")
  11.  
  12.  
  13. While(true)
  14.     If Ping(strHost) = true Then
  15.         If IsRunning(strFilename) = false Then
  16.             WScript.Echo "Internetverbindung vorhanden. Starte Programm."
  17.             objShell.Run(strPath & strFilename)
  18.         End If
  19.     Else
  20.         If IsRunning(strFilename) = true Then
  21.             Wscript.Echo "Keine Internetverbindung. Beende Programm."
  22.             objShell.Run("taskkill /IM " & strFilename)
  23.         End If
  24.     End If
  25.     Wscript.Sleep intRetry*1000
  26. Wend
  27.  
  28.  
  29. Function Ping(strHost)
  30.     Dim objPing, objStatus
  31.  
  32.     Ping = false
  33.  
  34.     Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
  35.     ExecQuery("SELECT * FROM Win32_PingStatus WHERE address = '" & strHost & "'")
  36.  
  37.     For Each objStatus in objPing
  38.         If objStatus.StatusCode = 0 Then
  39.             Ping = true
  40.             Exit Function
  41.         End If
  42.     Next
  43. End Function
  44.  
  45. Function IsRunning(strProcess)
  46.     Dim objProcess, objService
  47.    
  48.     IsRunning = false
  49.    
  50.     Set objService = GetObject("winmgmts:")
  51.    
  52.     For Each objProcess in objService.InstancesOf("Win32_Process")
  53.         If UCase(objProcess.name) = UCase(strProcess) Then
  54.             IsRunning = true
  55.             Exit Function
  56.         End If
  57.     Next
  58. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement