/// <summary> /// Launch AutoKMS /// </summary> public void RunAutoKMS() { // Start Logging string logPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + AutoKMSInstaller.AutoKMSInstaller.AutoKMSLogFileName; // Delete Log if Greater than 10MB FileInfo logFile = new FileInfo(logPath); if (logFile.Exists && logFile.Length >= 10485760) { CommonUtilities.FileDelete(logPath); } // Access Log using (_log = new StreamWriter(logPath, true)) { WriteLine("----------------------------------------"); // Get the Program File Version FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location); WriteLine("AutoKMS " + myFileVersionInfo.FileVersion + " Ran At " + DateTime.Now + "."); // Check for Recent BSOD if (BSODTest() && Settings.Default.LocalHostBypassUseDLLInjection) { // Log Early Termination WriteLine("A recent unexpected shutdown or BSOD occured."); WriteLine("AutoKMS will not continue until the next Scheduled run."); WriteLine("----------------------------------------"); // Remake AutoKMS Tasks if (AutoKMSInstaller.AutoKMSInstaller.IsAutoKMSCustomTaskInstalled() == false) { AutoKMSInstaller.AutoKMSInstaller.AutoKMSInstallPath = Environment.CurrentDirectory; AutoKMSInstaller.AutoKMSInstaller.MakeAutoKMSNormalTask(); } return; } // EZ-Activator Check bool ezActivator = false; String[] arguments = Environment.GetCommandLineArgs(); foreach (string argument in arguments) { if (String.Compare(argument, "/EZActivator", StringComparison.InvariantCultureIgnoreCase) == 0) { ezActivator = true; break; } } // Show Splash Screen Thread splashScreenThread = null; if (ezActivator) { splashScreenThread = new Thread(ShowSplashScreen); splashScreenThread.Start(); } // Activate Microsoft Office if (OfficeVersion.IsOfficeSupported()) { // Only Activate KMS Licenses LicenseList licenses = new LicenseListOffice(); if (!ezActivator) { licenses.List = licenses.GetListLicensed(); licenses.List = licenses.GetListKMS(); } else { licenses.List = licenses.GetListKMS(); } if (licenses.List.Count > 0) { // Handle KMS Server Service if (Regex.IsMatch(Settings.Default.KMSServerOffice, @"^(127(\.\d+){1,3}|[0:]+1|localhost)$") || String.Compare(Settings.Default.KMSServerOffice, Environment.MachineName, StringComparison.InvariantCultureIgnoreCase) == 0) { if (KMSServerServiceInstaller.KMSServerServiceInstaller.IsKMSServerServiceInstalled()) { Services.StartService(KMSServerServiceInstaller.KMSServerServiceInstaller.KMSServerServiceName); Settings.Default.UseKMSEmulator = false; WriteLine("Using KMS Server Service."); } else if (Settings.Default.UseKMSEmulator) { WriteLine("Using built-in KMS Server Emulator."); } else { WriteLine("WARNING: Attempting LocalHost KMS Activation without KMS Server Service or built-in KMS Server Emulator!"); } } else { WriteLine("Using KMS Server over the Network."); } if (!ezActivator) { WriteLine("Attempting To Activate Microsoft Office"); Write(ActivationState.AttemptActivationOffice(licenses, true, Settings.Default.KMSServerOffice, Settings.Default.KMSPortOffice, Settings.Default.KMSPIDOffice, Settings.Default.KMSHardwareID, Settings.Default.UseKMSEmulator, Settings.Default.RemoveKMSConnection, Settings.Default.KillProcessOnPort, Settings.Default.LocalHostBypassUseDLLInjection, Settings.Default.LocalHostBypassUseTAPAdapter, Settings.Default.LocalHostBypassUseWinDivertClient, Settings.Default.LocalHostBypassIPAddress, Settings.Default.LocalHostBypassIPSubnet)); WriteLine(string.Empty); } else { Write(EZActivator.RunEZActivator(licenses, true, Settings.Default.KMSServerOffice, Settings.Default.KMSPortOffice, Settings.Default.KMSPIDOffice, Settings.Default.KMSHardwareID, Settings.Default.UseKMSEmulator, Settings.Default.RemoveKMSConnection, Settings.Default.KillProcessOnPort, Settings.Default.LocalHostBypassUseDLLInjection, Settings.Default.LocalHostBypassUseTAPAdapter, Settings.Default.LocalHostBypassUseWinDivertClient, Settings.Default.LocalHostBypassIPAddress, Settings.Default.LocalHostBypassIPSubnet)); WriteLine(string.Empty); } } } // Activate Microsoft Windows if (OSVersion.IsWindowsSupported()) { // Only Activate KMS Licenses LicenseList licenses = new LicenseListWindows(); if (!ezActivator) { licenses.List = licenses.GetListLicensed(); licenses.List = licenses.GetListKMS(); } else { licenses.List = licenses.GetListKMS(); } if (licenses.List.Count > 0) { // Handle KMS Server Service if (Regex.IsMatch(Settings.Default.KMSServerWindows, @"^(127(\.\d+){1,3}|[0:]+1|localhost)$") || String.Compare(Settings.Default.KMSServerWindows, Environment.MachineName, StringComparison.InvariantCultureIgnoreCase) == 0) { if (KMSServerServiceInstaller.KMSServerServiceInstaller.IsKMSServerServiceInstalled()) { Services.StartService(KMSServerServiceInstaller.KMSServerServiceInstaller.KMSServerServiceName); Settings.Default.UseKMSEmulator = false; WriteLine("Using KMS Server Service."); } else if (Settings.Default.UseKMSEmulator) { WriteLine("Using built-in KMS Server Emulator."); } else { WriteLine("WARNING: Attempting LocalHost KMS Activation without KMS Server Service or built-in KMS Server Emulator!"); } } else { WriteLine("Using KMS Server over the Network."); } if (!ezActivator) { WriteLine("Attempting To Activate Microsoft Windows"); Write(ActivationState.AttemptActivationWindows(licenses, true, Settings.Default.KMSServerWindows, Settings.Default.KMSPortWindows, Settings.Default.KMSPIDWindows, Settings.Default.KMSHardwareID, Settings.Default.UseKMSEmulator, Settings.Default.RemoveKMSConnection, Settings.Default.KillProcessOnPort, Settings.Default.LocalHostBypassUseDLLInjection, Settings.Default.LocalHostBypassUseTAPAdapter, Settings.Default.LocalHostBypassUseWinDivertClient, Settings.Default.LocalHostBypassIPAddress, Settings.Default.LocalHostBypassIPSubnet)); WriteLine(string.Empty); } else { Write(EZActivator.RunEZActivator(licenses, true, Settings.Default.KMSServerWindows, Settings.Default.KMSPortWindows, Settings.Default.KMSPIDWindows, Settings.Default.KMSHardwareID, Settings.Default.UseKMSEmulator, Settings.Default.RemoveKMSConnection, Settings.Default.KillProcessOnPort, Settings.Default.LocalHostBypassUseDLLInjection, Settings.Default.LocalHostBypassUseTAPAdapter, Settings.Default.LocalHostBypassUseWinDivertClient, Settings.Default.LocalHostBypassIPAddress, Settings.Default.LocalHostBypassIPSubnet)); WriteLine(string.Empty); } } } // Hide Splash Screen if (ezActivator) { splashScreenThread.Abort(); } } // Remake AutoKMS Tasks if (AutoKMSInstaller.AutoKMSInstaller.IsAutoKMSCustomTaskInstalled() == false) { AutoKMSInstaller.AutoKMSInstaller.AutoKMSInstallPath = Environment.CurrentDirectory; AutoKMSInstaller.AutoKMSInstaller.MakeAutoKMSNormalTask(); } }
/// <summary> /// Launch AutoRearm /// </summary> public void RunAutoRearm() { // Start Logging string logPath = Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + AutoRearmInstaller.AutoRearmInstaller.AutoRearmLogFileName; // Delete Log if Greater than 10MB FileInfo logFile = new FileInfo(logPath); if (logFile.Exists && logFile.Length >= 10485760) { CommonUtilities.FileDelete(logPath); } // Access Log using (_log = new StreamWriter(logPath, true)) { // Get Lowest Grace Period if (OfficeVersion.IsOfficeSupported()) { // Rearm if we only have 5 days left LicenseList licenses = new LicenseListOffice(); if (RearmBase.LowestGraceDays(licenses) < 6) { // Get the Program File Version FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetEntryAssembly().Location); WriteLine("------------------------------------" + Environment.NewLine + "AutoRearm " + myFileVersionInfo.FileVersion + " Ran At " + DateTime.Now + "."); // Rearm if Possible, Restore Backup if Rearm Fails WriteLine("Rearming Office because grace period is almost expired."); if (RearmOffice.Rearm().Contains("failed")) { WriteLine("Failed to Rearm. Restoring License Backup."); string restoreoutput = LicenseBackup.RestoreOfficeTrustedStore("AutoRearmBackup", Environment.CurrentDirectory + "\\Backups\\" + OfficeVersion.GetOfficeName() + Path.DirectorySeparatorChar); if (restoreoutput.Contains("Failed") == false) { WriteLine("Successfully Restored License Backup. Rearming Office."); // Wait and Cycle OSPPSVC Services.StopOSPPSVC(); Thread.Sleep(2000); Services.StartOSPPSVC(); Thread.Sleep(2000); if (RearmOffice.Rearm().Contains("failed")) { WriteLine("Failed to Rearm."); } else { WriteLine("Successfully Rearmed."); } } } else { WriteLine("Successfully Rearmed."); } } } else { WriteLine("Office Is Not Installed!"); } } // Remake AutoRearm Tasks AutoRearmInstaller.AutoRearmInstaller.AutoRearmInstallPath = Environment.CurrentDirectory; //AutoRearmInstaller.AutoRearmInstaller.DeleteAutoRearmNormalTask(); AutoRearmInstaller.AutoRearmInstaller.MakeAutoRearmNormalTask(); }