// assumes correct product key is the only one installed public static bool KmsActivate(IPAddress ipa) { // set kms server address Logger.Debug("Setting KMS address"); ManagementObject sls = WmiQuery.GetFirst("SELECT * FROM SoftwareLicensingService"); sls.InvokeMethod("SetKeyManagementServiceMachine", new object[] { ipa.ToString() }); // get VL product object Logger.Debug("Getting Volume License product object"); ManagementObject wslp = WmiQuery.GetFirst( "SELECT ID FROM SoftwareLicensingProduct WHERE " + WINDOWS_ACTIVE_PRODUCT_WHERE); if (wslp == null) { Logger.Error("Volume License product not activated"); return(false); } // activate Windows Logger.Debug("Activating Windows"); wslp.InvokeMethod("Activate", new object[0]); // refresh licensing status Logger.Debug("Refreshing licensing status"); sls.InvokeMethod("RefreshLicenseStatus", new object[0]); return(true); }
public static void ClearProductKeys() { // uninstall all installed Windows product keys Logger.Debug("Querying installed licenses"); List <ManagementObject> licensedProducts = WmiQuery.GetAll( "SELECT ID FROM SoftwareLicensingProduct WHERE " + WINDOWS_ACTIVE_PRODUCT_WHERE); Logger.Debug("Removing " + licensedProducts.Count.ToString() + " installed license(s)"); foreach (ManagementObject p in licensedProducts) { p.InvokeMethod("UninstallProductKey", new object[0]); } }
public static void SetProductKey(string productKey) { // clear current product key(s) ClearProductKeys(); // install new product key ManagementObject sls = WmiQuery.GetFirst("SELECT * FROM SoftwareLicensingService"); Logger.Debug("Installing new Product key"); sls.InvokeMethod("InstallProductKey", new object[] { productKey }); // refresh licensing status Logger.Debug("Refreshing licensing status"); sls.InvokeMethod("RefreshLicenseStatus", new object[0]); }
public static List <Tap0901Device> GetAllTap0901Devices() { List <ManagementObject> devs = WmiQuery.GetAll( "SELECT NetConnectionID, PNPDeviceID FROM Win32_NetworkAdapter " + "WHERE ServiceName = 'tap0901'" ); List <Tap0901Device> wrappedDevs = new List <Tap0901Device>(); foreach (ManagementObject m in devs) { wrappedDevs.Add(new Tap0901Device(m)); } Logger.Debug("Found " + wrappedDevs.Count.ToString() + " Tap device(s)"); return(wrappedDevs); }
public static string GetProductKey() { string regPk = WinProdKeyFind.GetWindowsProductKeyFromRegistry(); if (regPk == null) { return(null); } // check if the product key is effectively installed List <ManagementObject> licensedProducts = WmiQuery.GetAll( "SELECT ID FROM SoftwareLicensingProduct WHERE " + "PartialProductKey = \"" + regPk.Substring(regPk.Length - 5) + "\" AND " + WINDOWS_PRODUCT_WHERE ); if (licensedProducts.Count > 0) { return(regPk); } return(null); }
private static ManagementObject GetVlmcsdService() => WmiQuery.GetFirst( "SELECT * FROM Win32_Service " + "WHERE Name = \"vlmcsd\" AND " + "StartMode <> \"Disabled\"" );
public static string GetWindowsSKU() => WmiQuery.GetFirst("SELECT Caption FROM Win32_OperatingSystem")["caption"]?.ToString();