From 102bc8f84703937fe2d73caff4950fff835a16ad Mon Sep 17 00:00:00 2001 From: jm33-m0 Date: Sat, 23 Oct 2021 00:44:51 -0700 Subject: [PATCH] fix #7 --- win10-activate/ActOffice.cs | 59 +++++++++++++++++++++++++------ win10-activate/MainWindow.xaml.cs | 9 ----- win10-activate/Util.cs | 3 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/win10-activate/ActOffice.cs b/win10-activate/ActOffice.cs index ff1269a..f27011e 100644 --- a/win10-activate/ActOffice.cs +++ b/win10-activate/ActOffice.cs @@ -18,13 +18,11 @@ public static void OfficeActivate() // ospp root string root = ""; - // make vol - Process makeVol = new Process(); + // procinfo ProcessStartInfo startInfo = new ProcessStartInfo { FileName = "cscript.exe", WorkingDirectory = @"C:\", - Arguments = @"//Nologo ospp.vbs /sethst:kms.jm33.me", CreateNoWindow = true, UseShellExecute = false, @@ -35,21 +33,18 @@ public static void OfficeActivate() // change KMS server mainW.Dispatcher.Invoke(() => { - // convert to VOL if needed root = mainW.OsppPath.Text; startInfo.WorkingDirectory = mainW.OsppPath.Text; startInfo.Arguments = "//Nologo ospp.vbs /sethst:" + mainW.TextBox.Text; }); - if (Util.YesNo("Convert to VOL? This might fail!", "Retail to VOL convertor")) - { - Retail2Vol(root); - } if (IsOfficeActivated(root)) { return; } + Retail2Vol(root); + Process kmsServer = new Process { StartInfo = startInfo @@ -113,11 +108,21 @@ public static bool IsOfficeActivated(string root) activate.Start(); string activateDbg = activate.StandardOutput.ReadToEnd(); activate.WaitForExit(); + // Check Office activation mainW.Dispatcher.Invoke(() => { + if (mainW.ShowDebug.IsChecked == true) + { + MessageBox.Show("Checking if Office is activated:\n" + activateDbg, + "Debug", + MessageBoxButton.OK, + MessageBoxImage.Asterisk); + } + if (activateDbg.Contains("activation successful") || - activateDbg.Contains("0xC004F009")) + activateDbg.Contains("0xC004F009") || + activateDbg.Contains("LICENSE STATUS: ---LICENSED---")) { mainW.button.Content = "Done! Click to exit"; mainW.button.IsEnabled = true; @@ -144,12 +149,45 @@ public static void Retail2Vol(string installRoot) * product key is of Office Pro Plus */ { - string dstatus = Util.RunProcess("cscript.exe", "//NoLogo ospp.vbs /dstatus", installRoot, false); + string dstatus; + try + { + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = "cscript.exe", + WorkingDirectory = installRoot, + Arguments = @"//Nologo ospp.vbs /dstatus", + + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardOutput = true, + WindowStyle = ProcessWindowStyle.Hidden + }; + + // check license status + Process checkLicense = new Process + { + StartInfo = startInfo + }; + checkLicense.Start(); + dstatus = checkLicense.StandardOutput.ReadToEnd(); + checkLicense.WaitForExit(); + } + catch (Exception err) + { + MessageBox.Show("Retail2Vol\n" + err.ToString(), "Exception caught", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + if (dstatus.ToLower().Contains("volume")) { return; } + if (!Util.YesNo("You are not using a VOL version, try converting?", "Retail2Vol")) + { + return; + } string licenseDir = installRoot + @"..\root\License"; string key, visioKey, version; @@ -186,6 +224,7 @@ public static void Retail2Vol(string installRoot) } else { + MessageBox.Show("No compatible Office version found, exit?", "Goodbye", MessageBoxButton.OK, MessageBoxImage.Stop); return; } diff --git a/win10-activate/MainWindow.xaml.cs b/win10-activate/MainWindow.xaml.cs index 1bd0132..56fcb02 100644 --- a/win10-activate/MainWindow.xaml.cs +++ b/win10-activate/MainWindow.xaml.cs @@ -27,15 +27,6 @@ private void Button_Click(object sender, RoutedEventArgs e) Application.Current.Shutdown(); } - if (office_option.IsChecked.Value) - // Office has to be vol - { - if (!Util.YesNo("If you are not using a VOL version, kms-activate will try to convert it", "Proceed?")) - { - return; - } - } - // Disable all buttons button.Content = "Please wait..."; button.IsEnabled = false; diff --git a/win10-activate/Util.cs b/win10-activate/Util.cs index 9540251..e1c6e4e 100644 --- a/win10-activate/Util.cs +++ b/win10-activate/Util.cs @@ -66,11 +66,12 @@ public static string RunProcess(string name, string args, string workdir, bool s } catch (Exception err) { - MessageBox.Show(err.ToString(), "Exception caught", MessageBoxButton.OK, MessageBoxImage.Error); + MessageBox.Show("RunProcess\n" + err.ToString(), "Exception caught", MessageBoxButton.OK, MessageBoxImage.Error); return ""; } string output = proc.StandardOutput.ReadToEnd().ToLower(); + proc.WaitForExit(); return output; }