Skip to content

Commit

Permalink
fix: office activation failure due to unhandled exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Dec 21, 2022
1 parent 8c65fec commit 9715831
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions win10-activate/ActOffice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ class ActOffice
public static MainWindow mainW = (MainWindow)Application.Current.MainWindow;
public static void OfficeActivate()
{
if (!OfficeEnv())
{
Application.Current.Shutdown();
}
MessageBox.Show("Make sure to open Office and agree to user terms", "Tips", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);

// debug info
string kmsServerDbg, activateDbg;

Expand Down Expand Up @@ -279,13 +273,18 @@ public static bool OfficeEnv()
}

string officepath = "";
mainW.OsppPath.Text = officepath;
RegistryKey officeBaseKey = localKey.OpenSubKey(@"SOFTWARE\Microsoft\Office");
if (officeBaseKey == null)
{
throw new Exception("Office not installed");
}
if (officeBaseKey.OpenSubKey(@"16.0", false) != null)
{
var k = officeBaseKey.OpenSubKey(@"16.0\Word\InstallRoot");
if (k == null)
{
throw new Exception("Office not installed");
throw new Exception("Office not installed or corrupted");
}

var val = k.GetValue("Path");
Expand All @@ -294,14 +293,14 @@ public static bool OfficeEnv()
throw new Exception("Office installation corrupted");
}
officeBaseKey.Close();
officepath= val.ToString();
officepath = val.ToString();
if (officepath.Contains("root"))
// Office 2019 can only be installed via Click-To-Run, therefore we get "C:\Program Files\Microsoft Office\root\Office16\",
// otherwise we get "C:\Program Files\Microsoft Office\Office16\"
{
// OSPP.VBS is still in "C:\Program Files\Microsoft Office\Office16\"
officepath = officepath.Replace("root", "");
mainW.button.Content += "Office 2019/2016";
mainW.button.Content += "Office 2019/2021";
}
else
{
Expand All @@ -322,10 +321,7 @@ public static bool OfficeEnv()
}
else
{
MessageBox.Show("Only works with Office 2010 and/or above", "Unsupported version", MessageBoxButton.OK, MessageBoxImage.Error);
mainW.button.Content = "Unsupported version";
mainW.windows_option.IsChecked = true;
return false;
throw new Exception("Only works with Office 2010 and/or above");
}
mainW.OsppPath.Text = officepath;

Expand Down

0 comments on commit 9715831

Please sign in to comment.