From 3680c40e231b42f5060083f348d0eb46d8922647 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 23 Apr 2015 00:03:44 -0600 Subject: [PATCH] Catch COM errors when connecting to WMI. --- gns3server/utils/interfaces.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gns3server/utils/interfaces.py b/gns3server/utils/interfaces.py index 79e4ef28..4123459d 100644 --- a/gns3server/utils/interfaces.py +++ b/gns3server/utils/interfaces.py @@ -58,10 +58,11 @@ def get_windows_interfaces(): import win32com.client import pywintypes - locator = win32com.client.Dispatch("WbemScripting.SWbemLocator") - service = locator.ConnectServer(".", "root\cimv2") + interfaces = [] try: + locator = win32com.client.Dispatch("WbemScripting.SWbemLocator") + service = locator.ConnectServer(".", "root\cimv2") # more info on Win32_NetworkAdapter: http://msdn.microsoft.com/en-us/library/aa394216%28v=vs.85%29.aspx for adapter in service.InstancesOf("Win32_NetworkAdapter"): if adapter.NetConnectionStatus == 2 or adapter.NetConnectionStatus == 7: @@ -70,7 +71,7 @@ def get_windows_interfaces(): interfaces.append({"id": npf_interface, "name": adapter.NetConnectionID}) except (AttributeError, pywintypes.com_error): - log.warn("could not use the COM service to retrieve interface info, trying using the registry...") + log.warn("Could not use the COM service to retrieve interface info, trying using the registry...") return _get_windows_interfaces_from_registry() return interfaces