From efb3c8056a0ba69f831303dac2d82e53511704f5 Mon Sep 17 00:00:00 2001 From: Notselwyn <68616630+Notselwyn@users.noreply.github.com> Date: Fri, 14 Apr 2023 21:18:08 +0200 Subject: [PATCH] fix: fixed crash when env var "computername" does not exist --- SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs index a157e95b..5294d825 100644 --- a/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs +++ b/SafeExamBrowser.SystemComponents/VirtualMachineDetector.cs @@ -136,7 +136,9 @@ namespace SafeExamBrowser.SystemComponents // check Windows timeline caches for current hardware config var deviceCacheKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey($"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\TaskFlow\\DeviceCache"); - if (deviceCacheKey != null) + var currHostname = System.Environment.GetEnvironmentVariable("COMPUTERNAME"); + + if (deviceCacheKey != null && currHostname != null) { foreach (var cacheId in deviceCacheKey.GetSubKeyNames()) { @@ -147,7 +149,6 @@ namespace SafeExamBrowser.SystemComponents continue; } - var currHostname = System.Environment.GetEnvironmentVariable("COMPUTERNAME").ToLower(); var cacheHostname = ((string) cacheKey.GetValue("DeviceName")).ToLower(); // windows timeline syncs with other hosts that a user has logged into: check hostname to only check this device