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
    6,222
    22,280
    210
    #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 ?
     
  2. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    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
    6,222
    22,280
    210
  4. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    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
    6,222
    22,280
    210
    Yeh, just cut out the license check. ;)
     
  6. Josh Cell

    Josh Cell MDL Developer

    Jan 8, 2011
    3,515
    7,171
    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
    6,222
    22,280
    210
    Josh i think the answer he's looking for is... yes :eek:
     
  8. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,112
    60
    :D

    Thanks guys :)