Page 1 of 1 1
Topic Options
#212674 - 2017-09-12 11:46 PM Convert WMIC code to WMI/Kix
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4414
Loc: USA
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.

Top
#212675 - 2017-09-13 12:01 AM Re: Convert WMIC code to WMI/Kix [Re: Allen]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2078
Loc: Tulsa, OK
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?

Top
#212676 - 2017-09-13 12:05 AM Re: Convert WMIC code to WMI/Kix [Re: ShaneEP]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4414
Loc: USA
Hmmm

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

Rechecking.

Top
#212677 - 2017-09-13 12:22 AM Re: Convert WMIC code to WMI/Kix [Re: Allen]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4414
Loc: USA
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. \:\)

Top
#212678 - 2017-09-13 09:36 AM Re: Convert WMIC code to WMI/Kix [Re: Allen]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1862
Loc: Hilversum, The Netherlands
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.

Top
#212679 - 2017-09-13 03:44 PM Re: Convert WMIC code to WMI/Kix [Re: Arend_]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1862
Loc: Hilversum, The Netherlands
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


Top
#212920 - 2017-11-21 10:58 AM Re: Convert WMIC code to WMI/Kix [Re: Arend_]
Arend_ Moderator Online   sleepy
MM club member
*****

Registered: 2005-01-17
Posts: 1862
Loc: Hilversum, The Netherlands
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

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 150 anonymous users online.
Newest Members
Hdrthtsr19956, Kylie99, msmile042, rayd8, HardKn0X
17597 Registered Users

Generated in 0.066 seconds in which 0.027 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org