From d76dbf6b40d5bb4144945bbb6b0d2e2ab8ff416f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20B=C3=BCchel?= Date: Mon, 31 Jul 2023 15:19:31 +0200 Subject: [PATCH] SEBWIN-717, #637: Fixed loading of MAC address for system info. --- .../SystemInfo.cs | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/SafeExamBrowser.SystemComponents/SystemInfo.cs b/SafeExamBrowser.SystemComponents/SystemInfo.cs index 476c45d3..638bb2ce 100644 --- a/SafeExamBrowser.SystemComponents/SystemInfo.cs +++ b/SafeExamBrowser.SystemComponents/SystemInfo.cs @@ -219,31 +219,22 @@ namespace SafeExamBrowser.SystemComponents try { - using (var searcher = new ManagementObjectSearcher("SELECT MACAddress FROM Win32_NetworkAdapterConfiguration WHERE DNSDomain IS NOT NULL")) + using (var searcher = new ManagementObjectSearcher("SELECT MACAddress FROM Win32_NetworkAdapterConfiguration WHERE DNSHostName IS NOT NULL")) using (var results = searcher.Get()) + using (var networkAdapter = results.Cast().First()) { - if (results != default && results.Count > 0) + foreach (var property in networkAdapter.Properties) { - using (var networkAdapter = results.Cast().First()) + if (property.Name.Equals("MACAddress")) { - foreach (var property in networkAdapter.Properties) - { - if (property.Name.Equals("MACAddress")) - { - MacAddress = Convert.ToString(property.Value).Replace(":", "").ToUpper(); - } - } + MacAddress = Convert.ToString(property.Value).Replace(":", "").ToUpper(); } } - else - { - MacAddress = UNDEFINED; - } } } - catch (Exception) + finally { - MacAddress = UNDEFINED; + MacAddress = MacAddress ?? UNDEFINED; } }