/// <summary> /// Install KMS Keys Automatically and Perform Activation of All KMS Licenses /// </summary> /// <param name="licenses">List of all Licenses</param> /// <param name="minimalOutput">Reduce the Amount of Output During Activation</param> /// <param name="kmsServer">KMS Host to Connect To</param> /// <param name="kmsPort">KMS Port to Connect To</param> /// <param name="kmsPid">KMS PID to apply to KMSEmulator</param> /// <param name="kmsHwid">KMS Hardware ID to apply to KMSEmulator</param> /// <param name="useKMSEmulator">Start a KMSEmulator Process</param> /// <param name="removeKMSConnection">Remove KMS Host and Port after Activation</param> /// <param name="killProcessOnPort">Force Start KMSEmulator by Killing Other Processes usign the KMS Port</param> /// <param name="useDLLInjection">Use DLL Injection to Force Localhost KMS Activation</param> /// <param name="useTAPAdapter">Use TAP Adapter to Force Localhost KMS Activation</param> /// <param name="useWinDivert">Use WinDivert Client to Force Localhost KMS Activation</param> /// <param name="localHostBypassIPAddress">IP Address of TAP Adapter NIC or WinDivert Client</param> /// <param name="localHostBypassIPSubnet">Subnet Mask for TAP Adapter or WinDivert Client Network</param> /// <returns>Activation Result of all KMS Licenses</returns> public static string RunEZActivator(LicenseList licenses, bool minimalOutput = true, string kmsServer = "127.0.0.2", int kmsPort = 1688, string kmsPid = "RandomKMSPID", string kmsHwid = "364F463A8863D35F", bool useKMSEmulator = true, bool removeKMSConnection = false, bool killProcessOnPort = false, bool useDLLInjection = false, bool useTAPAdapter = false, bool useWinDivert = false, string localHostBypassIPAddress = "10.3.0.1", string localHostBypassIPSubnet = "255.255.255.0") { // Show Activation Errors if No Licenses Exist if (licenses.GetListUnlicensed().Count == 0 && licenses.GetListLicensed().Count == 0) { return(LicenseErrorCode.ErrBroken); } // Show Activation Errors if No KMS Licenses Exist if (licenses.GetListKMS().Count == 0) { return(LicenseErrorCode.ErrNoKMS); } using (StringWriter output = new StringWriter()) { // Activated Windows Check if (licenses is LicenseListWindows && licenses.GetListPermanentlyActivated().Count > 0) { output.WriteLine("----------------------------------------"); output.WriteLine("Windows is already permanently activated."); output.WriteLine("----------------------------------------"); return(output.ToString()); } // Get All Possible KMS Keys KeyList keys = new KeyList(); if (licenses is LicenseListOffice) { keys = KeyBase.GetApplicableKeysList(OfficeVersion.GetOfficeName()); } else if (licenses is LicenseListWindows) { keys = KeyBase.GetApplicableKeysList(OSVersion.GetWindowsName()); } // Remove Trial Keys bool removedTrialKeys = false; output.WriteLine("----------------------------------------"); output.WriteLine("Removing Any Trial/Grace Keys."); foreach (LicenseInstance licenseKeys in licenses.GetListLicensed()) { if (licenseKeys.LicenseDescription.ToUpper().Contains("TRIAL") || licenseKeys.LicenseDescription.ToUpper().Contains("GRACE")) { if (licenses is LicenseListOffice) { KeyInstaller.UnInstallKeyByKeyOffice(licenseKeys.PartialProductKey); output.WriteLine("Removed Key for: " + licenseKeys.LicenseFamily + " (" + licenseKeys.PartialProductKey + ")."); removedTrialKeys = true; } else if (licenses is LicenseListWindows) { KeyInstaller.UnInstallKeyByKeyOffice(licenseKeys.PartialProductKey); output.WriteLine("Removed Key for: " + licenseKeys.LicenseFamily + " (" + licenseKeys.PartialProductKey + ")."); removedTrialKeys = true; } } } if (removedTrialKeys) { licenses.Refresh(); } // Install Uninstalled KMS Keys by SKUID Match bool installedKMSKeys = false; output.WriteLine("----------------------------------------"); output.WriteLine("Installing Any Matching Volume Keys."); if (licenses is LicenseListWindows && OSVersion.GetWindowsNumber() >= 10 && OSVersion.GetWindowsBuildNumber() >= 14393) { // Determine KMS Key if (licenses.GetListLicensed().Count > 0) { // SKU Match Existing Key foreach (LicenseInstance license in licenses.GetListLicensed()) { string editionId = license.LicenseFamily; try { // Check Key bool installKey = true; List <string> skuidListMatched = keys.GetSKUIDs(editionId); foreach (LicenseInstance licensed in licenses.GetListLicensed()) { if (skuidListMatched.Contains(licensed.SKUID)) { installKey = false; break; } } // Install Key if (installKey) { // Get All SKUIDs List <string> skuidListAll = new List <string>(); foreach (LicenseInstance licensed in licenses.GetListFull()) { skuidListAll.Add(licensed.SKUID); } // Get Matched Key foreach (string skuid in skuidListMatched) { if (skuidListAll.Contains(skuid)) { output.WriteLine("Installing " + keys.GetProductName(skuid) + " KMS Key (" + keys.GetProductKey(skuid) + ")."); KeyInstaller.InstallKeyWindows(keys.GetProductKey(skuid)); output.WriteLine("<Product key installation successful>"); installedKMSKeys = true; break; } } } } catch (Exception ex) { output.WriteLine(ex.Message); } } } else { // Edition ID Check using (RegistryKey registrySubKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", true)) { if (registrySubKey != null && registrySubKey.GetValue("EditionID") != null) { string editionId = registrySubKey.GetValue("EditionID").ToString(); try { if (keys.GetProductKey(editionId) != string.Empty) { output.WriteLine("Installing " + keys.GetProductName(editionId) + " KMS Key (" + keys.GetProductKey(editionId) + ")."); KeyInstaller.InstallKeyWindows(keys.GetProductKey(editionId)); output.WriteLine("<Product key installation successful>"); installedKMSKeys = true; } } catch (Exception ex) { output.WriteLine(ex.Message); } } } } } else { foreach (LicenseInstance license in licenses.GetListUnlicensed()) { if (keys.GetSKUIDs().Contains(license.SKUID)) { try { output.WriteLine("Installing " + keys.GetProductName(license.SKUID) + " KMS Key (" + keys.GetProductKey(license.SKUID) + ")."); if (licenses is LicenseListOffice) { KeyInstaller.InstallKeyOffice(keys.GetProductKey(license.SKUID)); output.WriteLine("<Product key installation successful>"); installedKMSKeys = true; } else if (licenses is LicenseListWindows) { KeyInstaller.InstallKeyWindows(keys.GetProductKey(license.SKUID)); output.WriteLine("<Product key installation successful>"); installedKMSKeys = true; } } catch (Exception ex) { output.WriteLine(ex.Message); } } } } output.WriteLine("----------------------------------------"); if (installedKMSKeys) { licenses.Refresh(); } // Perform Activation if (licenses is LicenseListOffice) { output.WriteLine("Attempting To Activate Microsoft Office"); output.Write(ActivationState.AttemptActivationOffice(licenses, minimalOutput, kmsServer, kmsPort, kmsPid, kmsHwid, useKMSEmulator, removeKMSConnection, killProcessOnPort, useDLLInjection, useTAPAdapter, useWinDivert, localHostBypassIPAddress, localHostBypassIPSubnet)); } else if (licenses is LicenseListWindows) { output.WriteLine("Attempting To Activate Microsoft Windows"); output.Write(ActivationState.AttemptActivationWindows(licenses, minimalOutput, kmsServer, kmsPort, kmsPid, kmsHwid, useKMSEmulator, removeKMSConnection, killProcessOnPort, useDLLInjection, useTAPAdapter, useWinDivert, localHostBypassIPAddress, localHostBypassIPSubnet)); } return(output.ToString()); } }
/// <summary> /// Obtain a Byte Array Representing PkeyConfig for Microsoft Windows PIDX Check from Program /// </summary> /// <param name="useBuiltIn">Load PkeyConfig from Installed Microsoft Windows</param> /// <param name="product">Name of Microsoft Windows Product to Choose based on selection</param> /// <returns>Byte Array Representation of PkeyConfig.xrm-ms</returns> public static byte[] GetPkeyConfigWindows(bool useBuiltIn = false, string product = "") { // Load PkeyConfig from System if (useBuiltIn) { return(GetBuiltInPkeyConfigWindows()); } // Choose by Product if Provided if (product != string.Empty) { switch (product) { case OSVersion.WinVista: case OSVersion.WinServer2008: return(Resources.pkeyconfig_winvista); case OSVersion.Win7: case OSVersion.WinServer2008R2: return(Resources.pkeyconfig_win7); case OSVersion.Win7ThinPC: return(Resources.pkeyconfig_win7thinpc); case OSVersion.Win7EmbeddedPOS: return(Resources.pkeyconfig_win7embeddedpos); case OSVersion.Win7EmbeddedStandard: return(Resources.pkeyconfig_win7embeddedstd); case OSVersion.Win8: case OSVersion.WinServer2012: return(Resources.pkeyconfig_win8); } } // Get PkeyConfig based on Microsoft Windows Edition switch (OSVersion.GetWindowsName()) { case OSVersion.WinVista: case OSVersion.WinServer2008: return(Resources.pkeyconfig_winvista); case OSVersion.Win7: case OSVersion.WinServer2008R2: return(Resources.pkeyconfig_win7); case OSVersion.Win7ThinPC: return(Resources.pkeyconfig_win7thinpc); case OSVersion.Win7EmbeddedPOS: return(Resources.pkeyconfig_win7embeddedpos); case OSVersion.Win7EmbeddedStandard: return(Resources.pkeyconfig_win7embeddedstd); case OSVersion.Win8: case OSVersion.WinServer2012: return(Resources.pkeyconfig_win8); default: throw new ApplicationException("No PkeyConfig Matching this Product!"); } }
/// <summary> /// Obtain a Byte Array List Representing PkeyConfig for Microsoft Windows PIDX Check from Program /// </summary> /// <param name="product">Name of Microsoft Windows Product to Choose based on selection</param> /// <returns>Byte Array Representations of PkeyConfig.xrm-ms files</returns> public static List <byte[]> GetPkeyConfigWindows(string product = "") { // Choose by Product if Provided if (String.IsNullOrWhiteSpace(product)) { // Get Microsoft Windows Edition product = OSVersion.GetWindowsName(); } // Choose PkeyConfigs based on Microsoft Windows Edition switch (product) { case OSVersion.WinVista: case OSVersion.WinServer2008: return(new List <byte[]> { Resources.pkeyconfig_winvista }); case OSVersion.Win7: case OSVersion.WinServer2008R2: return(new List <byte[]> { Resources.pkeyconfig_win7, Resources.pkeyconfig_win7embeddedpos, Resources.pkeyconfig_win7embeddedstd, Resources.pkeyconfig_win7thinpc, }); case OSVersion.Win7Embedded: return(new List <byte[]> { Resources.pkeyconfig_win7embeddedpos, Resources.pkeyconfig_win7embeddedstd, Resources.pkeyconfig_win7thinpc, Resources.pkeyconfig_win7 }); case OSVersion.Win8: case OSVersion.WinServer2012: return(new List <byte[]> { Resources.pkeyconfig_win8, Resources.pkeyconfig_win8csvlk, Resources.pkeyconfig_win8embeddedstd, Resources.pkeyconfig_win8embeddedindustry }); case OSVersion.Win8Embedded: return(new List <byte[]> { Resources.pkeyconfig_win8embeddedstd, Resources.pkeyconfig_win8embeddedindustry, Resources.pkeyconfig_win8, Resources.pkeyconfig_win8csvlk }); case OSVersion.Win81: case OSVersion.Win81Embedded: case OSVersion.WinServer2012R2: return(new List <byte[]> { Resources.pkeyconfig_win81, Resources.pkeyconfig_win81csvlk }); case OSVersion.Win10: case OSVersion.Win10Embedded: case OSVersion.WinServer2016: case OSVersion.WinServer2019: return(new List <byte[]> { // Threshold 1 Resources.pkeyconfig_win10_10240, Resources.pkeyconfig_win10csvlk_10240, // Threshold 2 Resources.pkeyconfig_win10_10586, Resources.pkeyconfig_win10csvlk_10586, // Redstone 1 Resources.pkeyconfig_win10_14393, Resources.pkeyconfig_win10csvlk_14393, // Redstone 2 Resources.pkeyconfig_win10_15063, Resources.pkeyconfig_win10csvlk_15063, // Redstone 3 Resources.pkeyconfig_win10_16299, Resources.pkeyconfig_win10csvlk_16299, // Redstone 4 Resources.pkeyconfig_win10_17134, Resources.pkeyconfig_win10csvlk_17134, // Redstone 5 Resources.pkeyconfig_win10_17763, Resources.pkeyconfig_win10csvlk_17763 }); default: throw new ApplicationException("No PkeyConfig Matching this Product!"); } }