Get Windows Partial Product Key

Discussion in 'Mixed Languages' started by Alphawaves, Jan 16, 2013.

  1. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,284
    180
    #1 Alphawaves, Jan 16, 2013
    Last edited by a moderator: Apr 20, 2017
    Ok if been looking at using WMI to get last 5 characters of product key..

    Code:
    public static string lst5 = "";
    
    foreach (ManagementObject check in new ManagementObjectSearcher("root\\CIMV2", "SELECT PartialProductKey FROM SoftwareLicensingProduct WHERE PartialProductKey <> null").Get())
    {
        lst5 = Convert.ToString(check["PartialProductKey"]);
         if (lst5 == string.Empty)
         {
             break;
         }
         else
         {
            textBox1.Text = lst5;
            break;
         }
    }
    Is there a better way of doing this ?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,106
    120
    #2 Josh Cell, Jan 16, 2013
    Last edited by a moderator: Apr 20, 2017
    A bit quicker method:

    Code:
    public static string GetPartialPkey()
    {
         ManagementObject mObj = new ManagementObjectSearcher("root\\CIMV2", "SELECT PartialProductKey, LicenseStatus FROM SoftwareLicensingProduct WHERE PartialProductKey <> null AND LicenseStatus = 1").Get().OfType<ManagementObject>().First();
        {
              return Convert.ToString(mObj["PartialProductKey"]);
        }
    }
    It will check for the product key where it is licensed and not null marshalling it quick... :)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,284
    180
    Nice Josh..:worthy::hug2:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,321
    60
    Is this a good method of confirming installed keys? Decrypt a key and then match the last 5 digits with WMI...
     
  5. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,284
    180
    Yeh, just cut out the license check. ;)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,519
    7,106
    120
    Basically is a kernel method that contains the real product keys stored on the tokens.dat, but only retrieve the last 5 digits.

    Registry decoding not always is accurate and can be modified or deleted without any issue.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  7. Alphawaves

    Alphawaves Super Moderator/Developer
    Staff Member

    Aug 11, 2008
    5,886
    20,284
    180
    Josh i think the answer he's looking for is... yes :eek:
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. QuantumBug

    QuantumBug MDL Developer

    Mar 7, 2012
    1,485
    1,321
    60
    :D

    Thanks guys :)