AllenAdministrator
(KiX Supporter)
2017-09-12 11:46 PM
Convert WMIC code to WMI/Kix

Having trouble converting this to usable code by kix.
 Code:
wmic path SoftwareLicensingService get OA3xOriginalProductKey


The above works as expected, but using the code below returns nothing, nor does a similar vbscript.

 Code:
$strComputer = "."
$objWMIService = GetObject("winmgmts:\\" + $strComputer + "\root\cimv2")
? @serror
$colItems = $objWMIService.ExecQuery("Select * from SoftwareLicensingService",,48)
? @serror
For each $objItem in $colItems
  ?  $ObjItem.OA3xOriginalProductKey
Next
? 'Press Any Key to close the window'
get $
 


Am I doing something stupid? Suggestions? Thanks.


ShaneEP
(MM club member)
2017-09-13 12:01 AM
Re: Convert WMIC code to WMI/Kix

I copied and pasted your posted code and it works fine on my Win10 computer. See results below (I changed license number to protect the innocent, but it did return a number).
 Quote:
The operation completed successfully.
The operation completed successfully.
VVVVV-WWWWW-XXXXX-YYYYY-ZZZZZ
Press Any Key to close the window

What OS are you using it on?


AllenAdministrator
(KiX Supporter)
2017-09-13 12:05 AM
Re: Convert WMIC code to WMI/Kix

Hmmm

Win10 here too... Tried it on two different ones.

Rechecking.


AllenAdministrator
(KiX Supporter)
2017-09-13 12:22 AM
Re: Convert WMIC code to WMI/Kix

My PC returns nothing. Not sure if that means my PC is activated differently or if there is something else going on. The other PC I tried, now works. Maybe I didn't test the final code, posted above, on it.

Okay. Thanks for checking it. \:\)


Arend_
(MM club member)
2017-09-13 09:36 AM
Re: Convert WMIC code to WMI/Kix

The code works fine (been using this in my inventory script for months now).
What this does, it retrieves the OEM product key which is imprinted in the BIOS.
This only works on Windows 10 and only on OEM machines such as HP, Dell, Lenovo etc.
For some machines you have to have the latest BIOS version for it to work.


Arend_
(MM club member)
2017-09-13 03:44 PM
Re: Convert WMIC code to WMI/Kix

I also converted/wrote a script to retrieve the installed ProductKey to match it with the OEM key.
This works most of the time.
If the retrieved key is VK7JG-NPHTM-C97JM-9MPGT-3V66T then the Windows 10 installation was either upgraded from a previous OS version or the OA3 key allows the OEM machine that originally had a OEM (OA2) marker in the BIOS for Windows 7 or 8 to be used for Windows 10.
So in that case you'll find a OA3 key using your code, but the Activation process changed it into the above mentioned key.

Anyway, the retrieval code for installed license only works for Windows 8 and above (8, 8.1 and 10) because MS changed the way to retrieve the code from Windows Vista and 7.
 Code:
$=SetOption("wow64alternateregview","on")
$reg = ReadValue("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId")
Dim $arrKey[]

$i=1
While ($i < LEN($reg))
  ReDim Preserve $arrKey[Ubound($arrKey)+1]
  $arrKey[Ubound($arrKey)] = Val("&"+SubStr($reg,$i,2))
  $i=$i+2
Loop

? "Installed Key: "+ConvertToKey($arrKey)

Function ConvertToKey($Key)
  ;Check if OS is Windows 8 
  $isWin8 = ($Key[66] / 6) And 1 
  $Key[66] = ($Key[66] And &F7) Or (($isWin8 And 2) * 4) 
  $KeyOffset = 52
  $i = 24
  $Maps = "BCDFGHJKMPQRTVWXY2346789"
  Do
    $Current = 0
    $j = 14
    Do
      $Current = $Current * 256
      $Current = $Key[$j+$KeyOffset] + $Current
      $Key[$j + $KeyOffset] = ($Current / 24)
      $Current = $Current Mod 24
      $j=$j-1
    Until $j < 0
    $i = $i-1
    $KeyOutput = SubStr($Maps, $Current+1, 1) + $KeyOutput
    $Last = $Current
  Until $i < 0

  $keypart1 = SubStr($KeyOutput, 2, $Last)
  $insert = "N"
  $KeyOutput = SubStr($KeyOutput, 2, LEN($KeyOutput))
  $KeyOutput = Join(Split($KeyOutput, $keypart1),$keypart1+$insert)
  If $Last = 0
    $KeyOutput = $insert+$KeyOutput
  EndIf

  $ConvertToKey=SubStr($KeyOutput,1,5)+"-"+SubStr($KeyOutput,6,5)+"-"+SubStr($KeyOutput,11,5)+"-"+SubStr($KeyOutput,16,5)+"-"+SubStr($KeyOutput,21,5)
EndFunction



Arend_
(MM club member)
2017-11-21 10:58 AM
Re: Convert WMIC code to WMI/Kix

Just for fun, here's a single line of code to retrieve the OA3 key:
 Code:
$strComputer = "."
? "OA3xOriginalProductKey = "+GetObject("winmgmts:\\"+$strComputer+"\root\cimv2").ExecQuery("Select * from SoftwareLicensingService").ItemIndex(0).OA3xOriginalProductKey