Optimized the code to find the office executable even more.

This commit is contained in:
Robin Krom 2022-08-17 23:08:59 +02:00
parent 3e88093846
commit af3c22c38c
No known key found for this signature in database
GPG key ID: BCC01364F1371490

View file

@ -35,16 +35,9 @@ internal static class OfficeUtils
foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse()) foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse())
{ {
using RegistryKey officeKey = Registry.LocalMachine.OpenSubKey(strRootKey + "\\" + officeVersion); using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot");
if (officeKey is null) continue;
using RegistryKey programKey = officeKey.OpenSubKey(strKeyName);
if (programKey is null) continue;
using RegistryKey installRootKey = programKey.OpenSubKey("InstallRoot");
if (installRootKey == null) continue; if (installRootKey == null) continue;
return $@"{installRootKey.GetValue("Path")}\{exeName}";
return installRootKey.GetValue("Path") + "\\" + exeName;
} }
} }
return string.Empty; return string.Empty;