private string ActivateProductKey(Guid pKeyId) { string nErrorcode = string.Empty; IntPtr hSLC = new IntPtr(); var hResult = SLOpen(ref hSLC); uint pcbValue = 0; IntPtr ppbValue = System.IntPtr.Zero; SLDATATYPE peDataType = new SLDATATYPE(); hResult = SLGetPKeyInformation(hSLC, ref pKeyId, "ProductSkuId", ref peDataType, ref pcbValue, ref ppbValue); if (hResult == 0) { byte[] bSkuId = new byte[pcbValue]; Marshal.Copy(ppbValue, bSkuId, 0, (int)pcbValue); Guid pSkuId = new Guid(bSkuId); hResult = SLActivateProduct(hSLC, ref pSkuId, null, null, null, null, 0); if (hResult == 0) { SLClose(hSLC); Console.WriteLine("KMS activation succeeded! Please refresh the license."); } else if (hResult == unchecked ((int)0xC004F074)) { nErrorcode = "0x" + hResult.ToString("X8"); Console.WriteLine("KMS activation failed, error code: " + nErrorcode); } } else { nErrorcode = "0x" + hResult.ToString("X8"); Console.WriteLine("KMS activation failed, error code: " + nErrorcode); } SLClose(hSLC); return(nErrorcode); }
public string ActivateOfficeProductKey(IntPtr hOSLC, string productKey, Guid pKeyId) { string nErrorcode = string.Empty; if (LoadOSPPC("OSPPCEXT.dll") == false) { return(ActivateProductKeyO(productKey)); } uint pcbValue = 0; IntPtr ppbValue = System.IntPtr.Zero; SLDATATYPE peDataType = new SLDATATYPE(); int hResult = SLGetPKeyInformationO(hOSLC, ref pKeyId, "ProductSkuId", ref peDataType, ref pcbValue, ref ppbValue); if (hResult == 0) { byte[] bSkuId = new byte[pcbValue]; Marshal.Copy(ppbValue, bSkuId, 0, (int)pcbValue); Guid pSkuId = new Guid(bSkuId); hResult = SLActivateProductO(hOSLC, ref pSkuId, null, null, null, null, 0); if (hResult == 0) { SLClose(hOSLC); Console.WriteLine("KMS activation succeeded! Please refresh the license."); } else if (hResult == unchecked ((int)0xC004F074)) { nErrorcode = "0x" + hResult.ToString("X8"); Console.WriteLine("KMS activation failed, error code: " + nErrorcode); } } else { nErrorcode = "0x" + hResult.ToString("X8"); Console.WriteLine("KMS activation failed, error code: " + nErrorcode); } SLClose(hOSLC); return(nErrorcode); }
internal static extern int SPPGetApplicationInformation(IntPtr hSLC, ref Guid pApplicationId, [InAttribute][MarshalAsAttribute(UnmanagedType.LPWStr)] string pwszValueName, ref SLDATATYPE peDataType, ref uint pcbValue, ref byte[] ppbValue);
public extern static int SLGetPKeyInformationO(IntPtr hOSLC, ref Guid pPKeyId, string pwszValueName, ref SLDATATYPE peDataType, ref uint pcbValue, ref IntPtr ppbValue);