mirror of
https://github.com/greenshot/greenshot
synced 2025-08-21 05:53:27 -07:00
OfficeUtils fix
(cherry picked from commit bfa75aea0208966f2a93a0e6ddb52270940417cd)
This commit is contained in:
parent
4524e2511e
commit
275d7b4149
1 changed files with 31 additions and 29 deletions
|
@ -1,43 +1,45 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
|
|
||||||
namespace Greenshot.Plugin.Office;
|
namespace Greenshot.Plugin.Office
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A small utility class for helping with office
|
|
||||||
/// </summary>
|
|
||||||
internal static class OfficeUtils
|
|
||||||
{
|
{
|
||||||
private static readonly string[] OfficeRootKeys = { @"SOFTWARE\Microsoft\Office", @"SOFTWARE\WOW6432Node\Microsoft\Office" };
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the path to the office exe
|
/// A small utility class for helping with office
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="exeName">Name of the office executable</param>
|
internal static class OfficeUtils
|
||||||
public static string GetOfficeExePath(string exeName)
|
|
||||||
{
|
{
|
||||||
string strKeyName = exeName switch
|
private static readonly string[] OfficeRootKeys = { @"SOFTWARE\Microsoft\Office", @"SOFTWARE\WOW6432Node\Microsoft\Office" };
|
||||||
{
|
|
||||||
"WINWORD.EXE" => "Word",
|
|
||||||
"EXCEL.EXE" => "Excel",
|
|
||||||
"POWERPNT.EXE" => "PowerPoint",
|
|
||||||
"OUTLOOK.EXE" => "Outlook",
|
|
||||||
"ONENOTE.EXE" => "OneNote",
|
|
||||||
_ => ""
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (string strRootKey in OfficeRootKeys)
|
/// <summary>
|
||||||
|
/// Get the path to the office exe
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="exeName">Name of the office executable</param>
|
||||||
|
public static string GetOfficeExePath(string exeName)
|
||||||
{
|
{
|
||||||
using RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(strRootKey);
|
string strKeyName = exeName switch
|
||||||
if (rootKey is null) continue;
|
|
||||||
|
|
||||||
foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse())
|
|
||||||
{
|
{
|
||||||
using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot");
|
"WINWORD.EXE" => "Word",
|
||||||
if (installRootKey == null) continue;
|
"EXCEL.EXE" => "Excel",
|
||||||
return $@"{installRootKey.GetValue("Path")}\{exeName}";
|
"POWERPNT.EXE" => "PowerPoint",
|
||||||
|
"OUTLOOK.EXE" => "Outlook",
|
||||||
|
"ONENOTE.EXE" => "OneNote",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (string strRootKey in OfficeRootKeys)
|
||||||
|
{
|
||||||
|
using RegistryKey rootKey = Registry.LocalMachine.OpenSubKey(strRootKey);
|
||||||
|
if (rootKey is null) continue;
|
||||||
|
|
||||||
|
foreach (string officeVersion in rootKey.GetSubKeyNames().Where(r => r.Contains(".")).Reverse())
|
||||||
|
{
|
||||||
|
using RegistryKey installRootKey = Registry.LocalMachine.OpenSubKey($@"{strRootKey}\{officeVersion}\{strKeyName}\InstallRoot");
|
||||||
|
if (installRootKey == null) continue;
|
||||||
|
return $@"{installRootKey.GetValue("Path")}\{exeName}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue