private static extern uint PidGenX ( string key, string fileName, string pidStart, IntPtr oemId, out DigitalProductId2 digitalProductId2, ref DigitalProductId3 digitalProductId3, ref DigitalProductId4 digitalProductId4 );
public static void CheckKey(string key, string pkeyConfigFileName, out DigitalProductId2 id2, out DigitalProductId3 id3, out DigitalProductId4 id4) { var osBuild = Environment.OSVersion.Version.Build; string ePidStart; if (osBuild >= 10000) { ePidStart = "03612"; } else if (osBuild >= 9600) { ePidStart = "06401"; } else if (osBuild >= 9200) { ePidStart = "05426"; } else { ePidStart = "55041"; } id3 = new DigitalProductId3(); id4 = new DigitalProductId4(); id3.size = DigitalProductId3.Size; id4.size = DigitalProductId4.Size; var hResult = PidGenX(key, pkeyConfigFileName, ePidStart, IntPtr.Zero, out id2, ref id3, ref id4); if (hResult != 0) { var innerException = (hResult & 0xffff0000) == 0x80070000 ? new Win32Exception(unchecked ((int)hResult)) : null; switch (hResult) { case 0x80070002: throw new FileNotFoundException("pkeyconfig database file not found", pkeyConfigFileName, innerException); default: throw new KmsException(Kms.StatusMessage(hResult), innerException); } } }