filimonic

Windows 7 Wait For Network Startup Script

Nov 23rd, 2012
16
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. strComputer = "."
  2. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  3. AdapterListQuery = "SELECT * FROM Win32_NetworkAdapter WHERE AdapterTypeID = 0 AND PhysicalAdapter = True "
  4. 'WScript.Echo "Scanning adapters"
  5. Set colAdapters = objWMIService.ExecQuery(AdapterListQuery)
  6. adapter_number = 0
  7. For Each objAdapter in colAdapters
  8.     If InStr(1,objAdapter.Name,"VMware",1) = 0 Then
  9.         'WScript.Echo " Adapter found:" & objAdapter.Name
  10.         adapter_number = adapter_number + 1
  11.     End If
  12. Next
  13. flag_stoploop = False
  14. cnt_timeout = 120 'Seconds
  15. time_start = Now()
  16. 'Check adapter number
  17. If adapter_number <= 0 Then
  18.         'WScript.Echo "No matching adapters found! Exiting!"
  19.         WScript.Quit
  20. End If
  21. 'WScript.Echo "Entering check cycle"
  22. while not flag_stoploop
  23.     If DateDiff("s",time_start,Now()) > cnt_timeout Then
  24.         flag_stoploop = True
  25.         'WScript.Echo "  (!) Stopping because of timeout"
  26.         WScript.Quit
  27.     End If
  28.     'WScript.Echo " Updating adapters list"
  29.     Set colAdapters = objWMIService.ExecQuery(AdapterListQuery)
  30.     For Each objAdapter in colAdapters
  31.         If InStr(1,objAdapter.Name,"VMware",1) = 0 Then
  32.             'WScript.Echo "  Checking adapter status:" & objAdapter.Name
  33.             WScript.Sleep 500
  34.             If (objAdapter.NetConnectionStatus = 2) Then
  35.                 flag_stoploop = True
  36.                 WScript.Echo "  (!) Stopping because of " & objAdapter.Name  & " is connected"
  37.                 Wscript.Quit
  38.             End If
  39.         End If
  40.     Next
  41. wend
RAW Paste Data